Trigger $(window).scroll();
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.
Just use:
// Trigger the scroll event
$(window).scroll();
Source:
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/
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');
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .