我正在尝试在这个插件中创建相同的鼠标悬停滚动效果:(尝试将鼠标悬停在箭头上)
http://coffeescripter.com/code/ad-gallery/
我有这个脚本:
$('#leftArrowScroller').bind('mouseover',function() {
setInterval(function(){
currentGalleryScroll -= 10;
$('#scrollMove').animate({'left':currentGalleryScroll+'px'});
},1);
});然而,这个脚本并不能达到同样的效果。正如我所希望的那样,它将div动画向左移动,但在每隔一段时间后都会暂停。有没有什么办法可以让滚动更流畅,就像链接中的一样?谢谢!
发布于 2012-02-21 16:27:39
如果你看一下插件使用的代码,你会得到以下函数:
function () {
var direction = 'left';
if($(this).is('.ad-forward')) {
direction = 'right';
};
thumbs_scroll_interval = setInterval(
function() {
has_scrolled++;
// Don't want to stop the slideshow just because we scrolled a pixel or two
if(has_scrolled > 30 && context.settings.slideshow.stop_on_scroll) {
context.slideshow.stop();
};
var left = context.thumbs_wrapper.scrollLeft() + 1;
if(direction == 'left') {
left = context.thumbs_wrapper.scrollLeft() - 1;
};
context.thumbs_wrapper.scrollLeft(left);
},
10
);
$(this).css('opacity', 1);
}注意它是如何做自己的动画的,在时间间隔内设置.scrollLeft()属性。您可能希望做类似的事情。
https://stackoverflow.com/questions/9374228
复制相似问题