{"id":610,"date":"2008-03-12T06:22:25","date_gmt":"2008-03-12T13:22:25","guid":{"rendered":"http:\/\/css-tricks.com\/3d-parralax-background-effect\/"},"modified":"2008-12-18T07:12:11","modified_gmt":"2008-12-18T14:12:11","slug":"3d-parralax-background-effect","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/3d-parralax-background-effect\/","title":{"rendered":"Starry Night: Incredible 3D Background Effect with Parallax"},"content":{"rendered":"

starrynight.png<\/p>\n

If you haven’t seen the mysteriously cool Silverback app<\/a> teaser page you should check it out. The Gorilla was designed by Jon Hicks<\/a> (yep! the same site with the cool body-border technique<\/a>). Make sure you resize your browser around when you visit the site to see the cool “parallax<\/a>” effect of the hanging vines. The site itself was designed by Paul Annett. Paul wrote an article on Think Vitamin on how he created that parallax effect<\/a>.<\/p>\n

I thought I would take the idea an explain it in a bit more detail, which a slightly different application, and offer up a download for those interested.<\/p>\n

What is Parallax?<\/h3>\n

You can think of motion parallax as what you see when you look out of a moving train. Bushes right alongside the train tracks will zip past your view, while cattle grazing in the field will appear to move more slowly across your view and the mountains in the background will hardly move at all.<\/strong> Parallax has particular relevance to astronomy. Not only because sci-fi movies use the effect all the time to create cool space effects, but because this effect is how we measure how far stars are away from our own solar system.<\/p>\n

Multiple Backgrounds with Parallax<\/h3>\n

In honor of this amazing effect and it’s relevance to science, I created Starry Night<\/a>. Starry night is a full-page background effect with three layers. Distant stars will only move a little bit as you resize the browser window, while closer stars will move faster. The effect is created with three page elements, all of which occupy the entire browser window. The body (“background”), a div (“midground”), and another div (“foreground”).<\/p>\n

<body>\r\n\t<div id=\"midground\"><\/div>\r\n\t<div id=\"foreground\"><\/div>\r\n<\/body><\/code><\/pre>\n

The body element will fill the entire screen by default, but we’ll have to style the other two divs with absolute positioning to do the same.<\/p>\n

body { \r\n\tbackground: url(images\/background.png) repeat 5% 5%;\r\n}\r\n#midground {\r\n\tbackground: url(images\/midground.png) repeat 20% 20%;\r\n\tposition: absolute;\r\n\ttop: 0; left: 0; right: 0; bottom: 0;\r\n\tz-index: 997;\r\n}\r\n#foreground {\r\n\tbackground: url(images\/foreground.png) repeat 90% 110%;\r\n\tposition: absolute;\r\n\ttop: 0; left: 0; right: 0; bottom: 0;\r\n\tz-index: 998;\r\n}<\/code><\/pre>\n

Both the midground and the foreground PNG files are alpha-transparent, so they will lay on top of each other nicely. The important part here is the % values you see in the background attribute. This controls the horizontal and vertical positioning, but in the context of this example, you can read that as “how fast you want it to move”. Also notice you can go beyond 100%, this means it will move at a faster rate than the rate of resizing the browser window.<\/p>\n

It is worth mentioning at this time that this effect just ain’t gonna happen in IE 6 or below. Between the bugs with PNG and the bugs with absolute positioning, it’s just not worth it.<\/em> In my example, I use a conditional stylesheet<\/a> to display a warning message.<\/p>\n

Where does my content go?<\/h3>\n

That’ll be up to you, notice in my example page<\/a> the small bit of content in the upper right. You could do something similar. Remember that any area you build to put content into will need to be absolutely positioned<\/strong> and have a higher z-index value<\/strong>. Otherwise, the absolutely positioned foreground and midground will cover up your content area and you won’t be able to select or click anything (if you can see it at all).<\/p>\n

[VIEW EXAMPLE PAGE]<\/a><\/p>\n

[DOWNLOAD EXAMPLE]<\/a>
\n.ZIP file inclues Photoshop document for the stars.<\/p>\n","protected":false},"excerpt":{"rendered":"

If you haven’t seen the mysteriously cool Silverback app teaser page you should check it out. The Gorilla was designed by Jon Hicks (yep! the same site with the cool body-border technique). Make sure you resize your browser around when you visit the site to see the cool “parallax” effect of the hanging vines. The […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[4],"tags":[],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":2508,"url":"https:\/\/css-tricks.com\/auto-moving-parallax-background\/","url_meta":{"origin":610,"position":0},"title":"Auto-Moving Parallax Background","date":"April 6, 2009","format":false,"excerpt":"A while back I did a little demo on parallax backgrounds. As a quick review, parallax is that effect where there are different layers of backgrounds that all move at a different rate creating a very unique 3D effect (think Sonic the Hedgehog). In that original demo, the only way\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/csstricks-uploads\/parallaxdemo.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":367270,"url":"https:\/\/css-tricks.com\/scroll-shadows-pure-css-parallax-game-back-on\/","url_meta":{"origin":610,"position":1},"title":"Scroll Shadows? Pure CSS Parallax? Game Back On.","date":"July 29, 2022","format":false,"excerpt":"Chris calls scroll shadows one his favorite CSS-Tricks of all time. Lea Verou popularized the pure CSS approach using four layered background gradients with some clever background-attachment magic. The result is a slick scrolling interaction that gives users a hint that additional content is available in a scrollable container. CodePen\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/01\/smooth-scroll.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":21471,"url":"https:\/\/css-tricks.com\/3d-inset-parallax-effect\/","url_meta":{"origin":610,"position":2},"title":"3D Inset Parallax Effect","date":"May 4, 2013","format":false,"excerpt":"The following is a guest post by Joshua Bader. Joshua noticed that certain 3D effects on the web could benefit from adjusting perspective as the web page is scrolled. I'll let him explain. People love to make flat things appear as if they're three-dimensional. There are two ways to pull\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":178538,"url":"https:\/\/css-tricks.com\/pure-css-parallax-scrolling-websites\/","url_meta":{"origin":610,"position":3},"title":"Pure CSS parallax scrolling websites","date":"August 11, 2014","format":false,"excerpt":"Keith Clark explains the core concept behind parallax scrolling (e.g. different elements scroll at different rates) with just CSS. It's a devilishly clever (yet simple) combination of 3D transforms to push the element \"away\" from the screen, affecting it's scroll rate, while adjusting the scale so the element appears at\u2026","rel":"","context":"In "Link"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":275322,"url":"https:\/\/css-tricks.com\/using-css-clip-path-to-create-interactive-effects-part-ii\/","url_meta":{"origin":610,"position":4},"title":"Using CSS Clip Path to Create Interactive Effects, Part II","date":"August 24, 2018","format":false,"excerpt":"This is a follow up to my previous post looking into clip paths. Last time around, we dug into the fundamentals of clipping and how to get started. We looked at some ideas to exemplify what we can do with clipping. We\u2019re going to take things a step further in\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2018\/08\/svg-clip-mask.gif?fit=800%2C400&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":299464,"url":"https:\/\/css-tricks.com\/ios-13-broke-the-classic-pure-css-parallax-technique\/","url_meta":{"origin":610,"position":5},"title":"iOS 13 Broke the Classic Pure CSS Parallax Technique","date":"November 27, 2019","format":false,"excerpt":"I know. You hate parallax. You know what we should hate more? When things that used to work on the web stop working without any clear warning or idea why. Way back in 2014, Keith Clark blogged an exceptionally clever CSS trick where you essentially use a CSS transform to\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/11\/cracked.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/610"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=610"}],"version-history":[{"count":1,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":1817,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/610\/revisions\/1817"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}