Prevent Auto Scrolling During Manual Scrolling in JavaScript
To prevent auto scrolling when scrolling manually in JavaScript, you can use the following code:
var scrolling = false;
window.addEventListener('scroll', function() {
scrolling = true;
});
setInterval(function() {
if (scrolling) {
// stop auto scrolling code here
scrolling = false;
}
}, 250);
This code adds an event listener to the window object to detect when the user is manually scrolling. When scrolling is detected, the 'scrolling' variable is set to true.
Then, a setInterval() function is used to check the value of 'scrolling' every 250 milliseconds. If 'scrolling' is true, it means the user is manually scrolling and the auto scrolling code can be stopped.
Once the auto scrolling is stopped, the 'scrolling' variable is set back to false to allow the auto scrolling to resume when the user is no longer manually scrolling.
原文地址: https://www.cveoy.top/t/topic/mGDE 著作权归作者所有。请勿转载和采集!