Sawny
Sawny

Reputation: 1423

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.

The code

EDIT: Problem solved. There was an if in my $(window).scroll(function() { }); that caused the problem.

Upvotes: 24

Views: 78332

Answers (3)

Just use:

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

Source:

Upvotes: 50

user3059993
user3059993

Reputation: 344

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');

Upvotes: 2

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195982

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/

Upvotes: 9

Related Questions