Timtest
Timtest

Reputation: 400

Scroll() function when refreshing pages

I would like to use the scroll() function to detect when I scrolldown the page. for example, this code :

$(window).scroll(function () {
    alert();
});    

My problem is that this code works when I'm at the top of the page and scrolldown, but when I'm not at the top of the page and I refresh the page, I have the alert BEFORE any scroll.

I would like it to work only when I scroll. NOT when I'm already at the middle of the page without scrolling yet.

Do you have any advice? I hope I'm clear.

Tim

Upvotes: 3

Views: 87

Answers (3)

Narayanan Sekar
Narayanan Sekar

Reputation: 1

If you are using jquery try to resolve by doing if condition in scrollTop() method. This will give u the scroller position.

Always better if u use JavaScript or jquery on document ready.

Upvotes: 0

Tom
Tom

Reputation: 188

Problem is, after a reload you are scrolling to the last position of your site.

You could set a timeout befor assigning the scroll event to window like:

setTimeout(function() {
 $(window).scroll(function () {
  alert();
 });  
}, 5000);

Upvotes: 2

Agu Dondo
Agu Dondo

Reputation: 13579

There's a plugin that detects up/down mouse wheel.

Upvotes: 1

Related Questions