将nicescroll链接到箭头按钮

时间:2013-07-16 03:55:52

标签: jquery nicescroll

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

关于我如何做到这一点的任何想法? (对不起,jquery我不是很好)

由于

3 个答案:

答案 0 :(得分:3)

我回答这个问题有点晚了,但这对其他人有用。

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

例如:

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

如果要在用户持续按下时继续滚动,可以使用keydown并以间隔更改scrolltop的值,并在keyup时清除该间隔。

希望这有帮助。

答案 1 :(得分: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;
}

这不是最佳解决方案,但它适用于垂直滚动...

答案 2 :(得分: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
    });
});

将#scroll-down,#scroll-up和#main替​​换为您自己的ID。通过更改100,您可以调整每次单击滚动的距离