Last active
October 30, 2020 12:28
-
-
Save timhudson/5484248 to your computer and use it in GitHub Desktop.
Scroll start/stop events using jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$(document).on('scrollstart', function() { | |
console.log('scroll started') | |
}) | |
$(document).on('scrollend', function() { | |
console.log('scroll ended') | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var lastScrollAt = Date.now() | |
, timeout | |
function scrollStartStop() { | |
var $this = $(this) | |
if (Date.now() - lastScrollAt > 100) | |
$this.trigger('scrollstart') | |
lastScrollAt = Date.now() | |
clearTimeout(timeout) | |
timeout = setTimeout(function() { | |
if (Date.now() - lastScrollAt > 99) | |
$this.trigger('scrollend') | |
}, 100) | |
} | |
$(document).on('scroll', scrollStartStop) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment