Trigger $(window).scroll();

Sawny picture Sawny · Oct 27, 2012 · Viewed 70.8k times · Source

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.

Answer

Vinícius Hipólito picture Vinícius Hipólito · Jul 28, 2014

Just use:

// Trigger the scroll event
$(window).scroll();

Source: