Jquery Nice 滚动不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11862656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery Nice scroll not working
提问by gaurang171
I am using Jquery nice Scroll bar for div, but when content of div increases dynamically its not showing scroll bar. Windows default scroll bar works fine if i remove nice scroll. Can anyone help me to solve this problem?
我正在为 div 使用 Jquery 漂亮的滚动条,但是当 div 的内容动态增加时,它不显示滚动条。如果我删除漂亮的滚动条,Windows 默认滚动条工作正常。谁能帮我解决这个问题?
Html
html
<div id="div-to-scroll">
</div>
Script
脚本
$(document).ready(function(e) {
var nice = $("#div-to-scroll").getNiceScroll();
$("#div-to-scroll").niceScroll();
$("#div-to-scroll").getNiceScroll().resize();
});
this is my code sample.
这是我的代码示例。
回答by gaurang171
Finally this works for me.
最后这对我有用。
$("#div-to-scroll").scroll(function(){
$("#div-to-scroll").getNiceScroll().resize();
});
回答by Karolis Gerbauskas
for me works just with
对我来说只是与
$("#div-to-scroll").mouseover(function() {
$("#div-to-scroll").getNiceScroll().resize();
});
回答by Code Spy
UPDATE: new function found!
更新:发现新功能!
var setScroll = function(i) {
if($(i).length>0)
$(i).niceScroll().updateScrollBar();
}
Call this function to Update niceScroll
调用这个函数来更新 niceScroll
setScroll(".classWithNiceScroll");
回答by Sandeep
Do this:
做这个:
// Scroll X Axis
$("#mydiv").getNiceScroll()[0].doScrollLeft(x, duration);
// Scroll Y Axis -
$("#mydiv").getNiceScroll()[0].doScrollTop(y, duration);
or:
或者:
// Scroll X Axis
$("#mydiv").getNiceScroll(0).doScrollLeft(x, duration);
// Scroll Y Axis -
$("#mydiv").getNiceScroll(0).doScrollTop(y, duration);
Note [0]
after getNiceScroll()
注意[0]
之后getNiceScroll()
回答by osyan
Some possible reasons:
1- Maybe you forgot to specify your div height. fix your div Height.
2- also if your div is float in width fix that width too.
Remmember that your DIV STYLE should have: overflow-y: hidden;
UPDATE
try using resize() function every time you scroll down:
一些可能的原因:
1- 也许您忘记指定您的 div 高度。修复你的 div 高度。
2- 同样,如果您的 div 在宽度上浮动,也要修复该宽度。
请记住,您的 DIV STYLE 应该具有:overflow-y: hidden;
UPDATE
每次向下滚动时尝试使用 resize() 函数:
$("div-to-scroll").slideDown(function(){
$("div-to-scroll").getNiceScroll().resize();
});
回答by Banty Roy
$("html").mouseover(function() {
$("html").getNiceScroll().resize();
});
To get the scroll bar on full body
获取全身滚动条