Skip to content

Instantly share code, notes, and snippets.

@technbuzz
Created December 22, 2015 13:53
Show Gist options
  • Save technbuzz/5f1405d7ef33cd192db3 to your computer and use it in GitHub Desktop.
Save technbuzz/5f1405d7ef33cd192db3 to your computer and use it in GitHub Desktop.
Simple Parallax Scrolling
///////////////////////////////////////////
// Paralax Effect
////////////////////////////////////////////
var el = document.getElementById('header-image');
window.addEventListener('scroll', function(){
var yPos = -(window.scrollY / 15);
var coords = '50% ' + yPos + 'px';
el.style.backgroundPosition = coords;
console.log(coords);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment