Skip to content

Instantly share code, notes, and snippets.

@williammalo williammalo/README.md forked from 140bytes/LICENSE.txt
Last active Oct 2, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Owner Author

commented Apr 5, 2012

@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
You can’t perform that action at this time.