Trigger $(window).scroll();
74,529
Solution 1
Just use:
// Trigger the scroll event
$(window).scroll();
Source:
Solution 2
Apply it to both body
and html
as it is not consistent.. (for example, FF uses the html
for scrolling while chrome uses the body
)
$("html, body").animate({scrollTop: someValue});
demo at http://jsfiddle.net/vzyVh/
Solution 3
You can try below code - here i am scrolling to top of my div tag which has id "one".
$('html,body').animate({ scrollTop: $('#one').offset().top }, 'slow');
Related videos on Youtube
Comments
-
Sawny almost 2 years
When I call
$("body").animate({scrollTop: someValue});
I want$(window).scroll(function() { });
to be called too. How can I achieve that?I have tried with
$(window).trigger("scroll")
and$(window).triggerHandler("scroll")
without success.EDIT: Problem solved. There was an
if
in my$(window).scroll(function() { });
that caused the problem.-
Om3ga over 11 yearswhat is animationType? And what if you use animationType inside inverted commas such as 'easeIn'?
-
Sawny over 11 years@al0neevenings That is not the problem. The body section scrolls, but the
$(window).scrollU();
doesn't get called. -
Gabriele Petrioli over 11 yearscan you also post what the method bound to
scroll
is doing ? -
Sawny over 11 years@GabyakaG.Petrioli oh... there was the problem. I had an if that prevented the function to run...
-
-
Sawny over 11 years1) Doesn't solve my problem. 2) Then the callback get called twice.
-
Gabriele Petrioli over 11 years@sawny, only if you have specifically made your CSS to allow both
html
andbody
to scroll. By default only one of those scrolls.. Additionally: thescroll
method applied towindow
is not called only once. It gets called for each scrolling step.. -
reallynice over 9 yearsMixed this answer with stackoverflow.com/a/12792245/1504300 for graceful scrolling to the bottom.