I am building webpage. It will look like single page but I am dealing with sections.On clicking on button controls i am hiding all the sections and showing particular section on the screen. So, can I do same control with Mouse pad scroll up and down?I have checked in google, I couldn't get proper solution. If this question is already posted, Please provide me the reference links.
Asked
Active
Viewed 2,303 times
0
-
did you tried this -> https://api.jquery.com/scroll/ – N1gthm4r3 Aug 25 '17 at 06:52
-
Yes, I have tried. But i am not getting proper response – Srinivas_N Aug 25 '17 at 06:53
-
I think there is perfect solution to detect touchpad scrolling but there is work-around. Delta speed increases 40 times. From there you can detect it. For more information, check this answer: https://stackoverflow.com/a/16696129/631803 – Vikasdeep Singh Aug 25 '17 at 07:01
-
Okay , I will check this – Srinivas_N Aug 25 '17 at 07:25
1 Answers
1
You can use the scroll event to respond to the user scrolling, like this:
$("#target").scroll(function(event) {
console.log("scroll event received:", event);
});
Note that the scroll events are triggered very frequently, so if you do anything that makes the browser work hard, you should take care to throttle the events, i.e. make sure you execute your code only every x milliseconds or so.
If you want to execute code only after the scroll has stopped, I have this fiddle for you.
function checkf(predf, callback, ms) {
window.setTimeout(function () {
if (predf()) {
callback();
return;
}
checkf(predf, callback, ms);
}, ms);
}
function afterScrollStops(func) {
var ms = 100, // interval to perform the scroll position check
oldX = $(document).scrollLeft(),
oldY = $(document).scrollTop();
function startf() {
$(document).one("scroll", function () {
checkf(function () {
var newX = $(document).scrollLeft(),
newY = $(document).scrollTop(),
stoppedScrolling = newX === oldX && newY === oldY;
oldX = newX;
oldY = newY;
return stoppedScrolling;
}, function () {
func();
startf();
}, ms);
});
}
startf();
}
afterScrollStops(function () {
console.log("user stopped scrolling");
});
In this example, the callback function passed to the afterScrollStops function is executed after the user has stopped scrolling.

Patrick Hund
- 19,163
- 11
- 66
- 95