问题
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.
The code
EDIT:
Problem solved. There was an if in my $(window).scroll(function() { }); that caused the problem.
回答1:
Just use:
// Trigger the scroll event
$(window).scroll();
Source:
- http://www.w3schools.com/jquery/event_scroll.asp
- https://api.jquery.com/scroll/
回答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/
回答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');
来源:https://stackoverflow.com/questions/13098988/trigger-window-scroll