Skip to content

Instantly share code, notes, and snippets.

@timhudson
Last active October 30, 2020 12:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save timhudson/5484248 to your computer and use it in GitHub Desktop.
Save timhudson/5484248 to your computer and use it in GitHub Desktop.
Scroll start/stop events using jQuery
$(function() {
$(document).on('scrollstart', function() {
console.log('scroll started')
})
$(document).on('scrollend', function() {
console.log('scroll ended')
})
})
(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