Michael.Lumley
Michael.Lumley

Reputation: 2385

$(window).scroll function will not execute unless I call it manually

I'm trying to get jquery to run some code every time that the window is scrolled. The function works fine if I call it from some other function (for example, calling $(window).scroll from inside another working function, but will not execute natively on a scroll itself. Any ideas what could cause this problem?

For example:

$('.someDiv').click(function() {
    $(window).scroll();
});

$(window).scroll(function() {
    //do some code
});

'some code' only executes when I click on "someDiv" but will not execute on the scrolling of the window.

Upvotes: 0

Views: 169

Answers (2)

Super Hornet
Super Hornet

Reputation: 2907

try this:

 $(window).resize(function() {
 $(window).scroll();

});

Upvotes: 0

Tomzan
Tomzan

Reputation: 2818

try binding to body:

$('body').scroll(function(){
     //Do Something
})

Upvotes: 1

Related Questions