简体   繁体   English

在图片库中使用jQuery自动水平滚动?

[英]Auto scroll horizontally using jquery in image gallery?

Ok so I am making an Image Gallery. 好的,我在制作图片库。 I laid thumbnails horizontally in a div under the big pictures. 我在大图片下面的div中水平放置了缩略图。 img this is a snapshot of it. img这是它的快照。

I want the thumbnails div to scroll with the big pictures as the user clicks on the next button. 当用户单击下一步按钮时,我希望缩略图div与大图片一起滚动。 I have tried 我努力了

$("#next").click(function({$(".slider_thumbnail").animate({scrollLeft: 300px})});

but this just works first time and doesn't work second time when user clicks on next button. 但这仅在第一次使用时有效,而在用户单击“下一步”按钮时则无法第二次使用。

I think there is a problem with scrollLeft: 300px . 我认为scrollLeft: 300px存在问题。 When you use this property, the element will be moved to the absolute scroll position of 300px at first time, and when you click next button again, it will not move because i already has the same scroll position. 当您使用此属性时,元素将在第一次移动到绝对滚动位置300px,并且当您再次单击next按钮时,它不会移动,因为我已经具有相同的滚动位置。 You should use scrollLeft: "+=300" for continuous working. 您应该使用scrollLeft: "+=300"进行连续工作。 Please take a look at http://api.jquery.com/animate/ 请看看http://api.jquery.com/animate/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM