Hello everyone, I'm currently working on creating a carousel. I have used list items with images inside and am using scroll to navigate to a specific list item. However, when clicking on a thumbnail (let's say the 2nd one), it scrolls to the image inside the LI and sets the image margin-left to 0px. What I really want is for the scroll to center the image instead.
Try clicking on the 4th thumb to view the desired effect.
I have created a fiddle for reference: MyFiddle
jQuery(document).ready(function($) {
$("#fourthThumb").click(function() {
$('html, body').animate({
scrollLeft: $("#fourthImage").offset().left
}, 2000);
});
});
Any suggestions on how to stop the scroll once the 4th image is centered would be greatly appreciated. Thank you.