jQuery – How to detect how many times a user scrolled down and up [duplicate]

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

I want to detect when a user scroll down and when a user scroll up and to keep the evidence using a counter.

I’ve seen previously solutions about how to detect if a user scrolled down or up, but I found it really hard to keep that evidence on a counter.

What I need:
When an user scroll down the counter will increment and when an user scroll up the counter will decrement.

The problem that I’m facing is:

$(window).scroll(function() {
var scroll = $(window).scrollTop();
)};

If I scroll down once with 50px ( for example ), the scroll variable will take the following values : 1,2,3,4,5…until 50. So I have 50 increments, even if I scrolled down only once.

I’d really appreciate your help,
Thank you a lot!

‫أضف إجابة

تصفح
تصفح

مجهول يجيب