Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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