Skip to content

Instantly share code, notes, and snippets.

@appel
Forked from cheh/background-scroll.js
Last active April 5, 2019 20:22
Show Gist options
  • Save appel/2f0d3692f34d55a5a63bb84f57e92578 to your computer and use it in GitHub Desktop.
Save appel/2f0d3692f34d55a5a63bb84f57e92578 to your computer and use it in GitHub Desktop.
Slow down background image scroll speed
var body = document.body,
doc = document.documentElement,
hAlign = 'center',
divideBy = 4;
$(window).scroll(function()
{
body.style.backgroundPosition = hAlign + " " + (0 - (Math.max(doc.scrollTop, body.scrollTop) / divideBy)) + "px";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment