Jquery Nice scroll not working
Asked Answered
S

6

9

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?

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.

Solfa answered 8/8, 2012 at 10:34 Comment(4)
sry ;-) i tought the current code state :-)Geibel
hmm should work with simple $("#div-to-scroll").niceScroll(); ... strangeGeibel
id or class div-to-scroll ? ;-)Geibel
sorry its id i forgot to change itSolfa
S
18

Finally this works for me.

$("#div-to-scroll").scroll(function(){
  $("#div-to-scroll").getNiceScroll().resize();
});
Solfa answered 9/8, 2012 at 4:37 Comment(0)
S
11

for me works just with

$("#div-to-scroll").mouseover(function() {
    $("#div-to-scroll").getNiceScroll().resize();
});
Sword answered 5/12, 2012 at 17:28 Comment(1)
Where did the mouseover come from?Kirstenkirsteni
M
2

UPDATE: new function found!

 var setScroll = function(i) {
        if($(i).length>0)
        $(i).niceScroll().updateScrollBar();
} 

Call this function to Update niceScroll

setScroll(".classWithNiceScroll");
Mccallister answered 1/2, 2014 at 12:44 Comment(0)
M
1

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:

$("div-to-scroll").slideDown(function(){
  $("div-to-scroll").getNiceScroll().resize();
});
Manisa answered 8/8, 2012 at 11:10 Comment(4)
Yes that all i have done. the thing is when window load it works but after i start to append content its not working.Solfa
@keyuratcodebins.com what happen after you append content? does it stop scrolling or it show all the content at the same time?Manisa
@keyuratcodebins.com try using resize() function every time you scroll downManisa
I have the same problem, I found that if I switch tabs on chrome and go back it starts working. any ideas?Suiting
L
1
$("html").mouseover(function() {
    $("html").getNiceScroll().resize();
});

To get the scroll bar on full body

Leonie answered 17/7, 2013 at 8:0 Comment(2)
The 2nd line has an extra # .Fibula
@Fibula Yes, Just follow the syntax. (Selector is immaterial here)Leonie
S
1

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()

Strict answered 13/10, 2014 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.