I'm trying to make a scrolling image that switches to a different 16:9 section using navigation buttons. Everything works, except jQuery seems to be limiting if(igBase.css('left') > igMaxLeft)
to -1200px or greater, even though igMaxLeft
is, for example, -2600px. Is there any reason for this behavior? The math looks right to me.
var igWrap = $('.infographic-wrapper');
var igBase = $('.infographic-base');
var igPrev = $('.infographic-previous');
var igNext = $('.infographic-next');
var igFrameWidth = igWrap.css('width');
var igMaxLeft = parseInt(igBase.css('width'), 10) + parseInt(igFrameWidth, 10);
igMaxLeft = '-' + igMaxLeft + 'px';
igPrev.click(function(){
if(igBase.css('left') < '0px'){
igBase.css('left','+=' + igFrameWidth);
}
});
igNext.click(function(){
if(igBase.css('left') > igMaxLeft){
igBase.css('left','-=' + igFrameWidth);
}
});
Here's the full example: https://codepen.io/arinthros/pen/YejRey