Skip to content

Instantly share code, notes, and snippets.

View benrobertsonio's full-sized avatar

Ben Robertson benrobertsonio

View GitHub Profile
@benrobertsonio
benrobertsonio / lazy-video-loader.js
Last active November 4, 2019 22:02
Lazy Loading Video Based on Connection Speed
class LazyVideoLoader {
constructor() {
this.videos = [].slice.call(document.querySelectorAll('.hero__bgvideo'));
// Abort when:
// - The browser does not support Promises.
// - There no videos.
// - If the user prefers reduced motion.
// - Device is mobile.
if (
@benrobertsonio
benrobertsonio / scrollchange.js
Last active January 16, 2017 21:53
A simple javascript module for adding a class to an element depending if it is visible or not.
// Use it like this:
// ScrollChange.init('.featured-on', 'featured-on--fixed');
var ScrollChange = {
element: '',
windowHeight: '',
elementTop: '',
lastScrollTop: 0,
delta: 50,
didScroll: false,