Skip to content

Instantly share code, notes, and snippets.

@onigetoc
Forked from timhudson/app-code.js
Created September 29, 2020 04:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save onigetoc/ae2a55beb26ea97b18ee3feb4e5cd345 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