Im have written a small function that basically takes the currentPosition value as a parameter works out if that number is equal to the overall number of slides and if it isnt adds 1 to the value, unfortunately though my incremented number never seems to move from 1. Can anyone advise me where I may be going wrong?
var currentPosition = 0;
var slideWidth = 320;
var numberOfSlides = sliderSlides.children.length;
console.log('Number of slides = ', numberOfSlides);
//Remove scrollbar in js
sliderCtn.style.overflow = 'hidden';
//Set .slides width equal to total width of all slides
sliderSlides.style.width = slideWidth * numberOfSlides + 'px';
// Direction click handlers
sliderDirNext[det.clickEvent] = function(e) {
next(currentPosition);
sliderSlides.style.left = slideWidth*(-currentPosition) + 'px';
console.log('Slide width ', slideWidth);
stopEvent(e);
};
function next(currentPosition){
if( currentPosition === numberOfSlides ) {
return false;
} else {
currentPosition += 1;
console.log('Next current position = ', currentPosition);
return true;
}
}
Solution. Though, there is most likely a better one if you provide more context:
After OP Update:
Simply removing the
nextfunctioncurrentPositionparameter should resolve your issue, given the rest of your logic is sound.