Skip to content

Instantly share code, notes, and snippets.

@lesleh
Created September 11, 2017 15:53
Show Gist options
  • Save lesleh/7cf4e18f005f536bfc16b6fcc7ab9eea to your computer and use it in GitHub Desktop.
Save lesleh/7cf4e18f005f536bfc16b6fcc7ab9eea to your computer and use it in GitHub Desktop.
Disable unintersected animations
/* global IntersectionObserver */
(function () {
'use strict'
var selectors = '.home-hero, .site-header__logo'
function callback (entries) {
var entry = entries[0]
$(entry.target).css('animation', entry.isIntersecting ? '' : 'none')
}
// Apply listeners to all animated gradient elements
$(function () {
var observer = new IntersectionObserver(callback)
$(selectors).each(function (i, e) {
observer.observe(e)
})
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment