我希望能夠將自定義箭頭按鈕鏈接到Nicescroll腳本,以便在有人單擊向上/向下按鈕時發生滾動(除了現有的按鍵和鼠標滾輪功能已經存在)。將nicescroll鏈接到箭頭按鈕
關於如何做到這一點的任何想法? (對不起,我沒有那麼大的jQuery)
感謝
我希望能夠將自定義箭頭按鈕鏈接到Nicescroll腳本,以便在有人單擊向上/向下按鈕時發生滾動(除了現有的按鍵和鼠標滾輪功能已經存在)。將nicescroll鏈接到箭頭按鈕
關於如何做到這一點的任何想法? (對不起,我沒有那麼大的jQuery)
感謝
我回答這個問題有點晚了,但是這可能是爲別人有用。
您可以通過更改使用nicescroll的容器的scrolltop來實現此目的。 Nicescroll自動更改滾動條,因此您不必擔心這一點。
例如:
$(ARROW).click(function() { $(SCROLLCONTAINER).scrollTop($(SCROLLCONTAINER).scrollTop() + 50); });
如果你想繼續滾動,當用戶保持按下你可以使用的keydown,並與間隔改變scrollTop的值,當KEYUP清除間隔。
希望這會有所幫助。
在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;
}
這不是最好的解決辦法,但它在垂直滾動中工作...
我知道這是有點晚了,但我正在尋找一個解決同樣的問題,我終於結束了這一點,這在我的情況非常完美:
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,您可以調整每次點擊滾動的距離