animate of jQuery
method can solve your problem. You can change the margin of your div .insta
according to the size of the photos, and animate()
gives you this transition effect. If you copy
jQuery( '.right-direction' ).on( "click", function() {
jQuery('.insta').animate({
marginLeft: "-=250px",
},1000, function() {
console.log ('moveu');
});
});
right in the console of your site, you will see that the right button now causes all your content to move to the left. You can use the same logic for the left button. It is worth remembering that the above code does not check if the images are finished or not, it just transitions the margin. This check will depend on the number of images you have.
EDIT :
I think the following code reproduces the effect you're looking for:
var offset = 0;
var TOTAL_IMAGENS = 10; //contei a partir do seu HTML. Você pode chegar neste valor na maneira como achar melhor
if (offset === 0){
jQuery('.left-direction').hide();
}
jQuery( '.right-direction' ).on( "click", function() {
jQuery('.insta').animate({
marginLeft: "-=250px",
},1000, function() {
++offset;
console.log(offset);
jQuery('.left-direction').show();
if(offset === TOTAL_IMAGENS){
jQuery('.right-direction').hide();
}
});
});
jQuery( '.left-direction' ).on( "click", function() {
jQuery('.insta').animate({
marginLeft: "+=250px",
},1000, function() {
--offset;
console.log(offset);
jQuery('.right-direction').show();
if(offset === 0){
jQuery('.left-direction').hide();
}
});
});
See that this code is not fully optimized (at various times, I run the jQuery('.left-direction').show();
and jQuery('.right-direction').show();
lines unnecessarily but, as a proof of concept, I believe the code is fine.If you want to be more objective, can control with two flags whether the buttons are there or not.
Basically, I set a variable called offset
that will be incremented or decremented as you click the left and right buttons. As at the beginning, there will be no image on the left, I already hide the arrow from the left (although this you can set in CSS and save a bit on your JS). If my offset
grows to the point of being the total number of photos, I hide the right arrow. Logic is basically this. As I said, this code is far from great, but I think it already gives you a good idea.