Skip to content

Instantly share code, notes, and snippets.

@williammalo
Forked from 140bytes/LICENSE.txt
Last active October 2, 2015 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williammalo/2278564 to your computer and use it in GitHub Desktop.
Save williammalo/2278564 to your computer and use it in GitHub Desktop.
paralaxr

Add parallax scrolling to a page's background.

onscroll=function(){document.body.style.backgroundPosition="0 "+pageYOffset>>1+"px"}
onscroll=function(){document.body.style.backgroundPosition="0 "+pageYOffset>>1+"px"}
{
"name": "paralaxr",
"description": "Add parallax scrolling to a page's background.",
"keywords": [
"parallax",
"css",
"background",
"3d"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>undefined</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function(){ /* the code here should be identical to the entry. */ }
document.getElementById( "ret" ).innerHTML = myFunction()
</script>
@atk
Copy link

atk commented Apr 5, 2012

Should be (...>>1) instead of (.../2), because .5px can result in problems in older browsers and ~ IEs. Nice idea, anyway.

@williammalo
Copy link
Author

@atk Good idea! Decimals in pixel based positioning result in crazy antialiasing that probably affect performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment