Run Jquery function on window events: load, resize, and scroll?

The Solution to Run Jquery function on window events: load, resize, and scroll? is


You can use the following. They all wrap the window object into a jQuery object.

Load:

$(window).load(function () {
    topInViewport($("#mydivname"))
});

Resize:

$(window).resize(function () {
   topInViewport($("#mydivname"))
});

Scroll

$(window).scroll(function () {
    topInViewport($("#mydivname"))
});

Or bind to them all using on:

$(window).on("load resize scroll",function(e){
    topInViewport($("#mydivname"))
});

~ Answered on 2013-03-27 17:20:18


Most Viewed Questions: