2013-07-16 49 views
2

我希望能够将自定义箭头按钮链接到Nicescroll脚本,以便在有人单击向上/向下按钮时发生滚动(除了现有的按键和鼠标滚轮功能已经存在)。将nicescroll链接到箭头按钮

关于如何做到这一点的任何想法? (对不起,我没有那么大的jQuery)

感谢

回答

3

我回答这个问题有点晚了,但是这可能是为别人有用。

您可以通过更改使用nicescroll的容器的scrolltop来实现此目的。 Nicescroll自动更改滚动条,因此您不必担心这一点。

例如:

$(ARROW).click(function() { $(SCROLLCONTAINER).scrollTop($(SCROLLCONTAINER).scrollTop() + 50); });

如果你想继续滚动,当用户保持按下你可以使用的keydown,并与间隔改变scrollTop的值,当KEYUP清除间隔。

希望这会有所帮助。

1

在niceScroll上找到对象这一行:

rail.append(cursor); 

然后将其装:

var cursor_wrapper = $(document.createElement('div')); 
cursor_wrapper.css({width: '100%', height: '100%'}); 
cursor_wrapper.addClass('cursor-wrapper'); 
rail.append(cursor_wrapper); 
cursor_wrapper.append(cursor); 

然后添加CSS:

.nicescroll-rails{ 
    background: url('../img/scroll-top-arrow.png') no-repeat center top; 
} 
.cursor-wrapper{ 
    background: url('../img/scroll-bottom-arrow.png') no-repeat center bottom; 
    cursor: pointer; 
} 

这不是最好的解决办法,但它在垂直滚动中工作...

1

我知道这是有点晚了,但我正在寻找一个解决同样的问题,我终于结束了这一点,这在我的情况非常完美:

var scrolled=0; 

jQuery("#scroll-down").on("click" , function(){ 
    scrolled=scrolled+100; 
    jQuery("#main").animate({ 
     scrollTop: scrolled 
    }); 
}); 
jQuery("#scroll-up").on("click" , function(){ 
    scrolled=scrolled-100; 
    jQuery("#main").animate({ 
     scrollTop: scrolled 
    }); 
}); 

#替换向下滚屏,#无滚动和#main与你自己的ID。通过更改100,您可以调整每次点击滚动的距离