Use background-attachment for Parallax scrolling

Source: Internet
Author: User

Parallax scrolling refers to moving multi-layer backgrounds at different speeds to form a three-dimensional motion effect and bring a very good visual experience. As a hot trend in web design this year, more and more websites are applying this technology.

Don't understand can first look at the effect of eBay: http://www.ebay.com/new/

In fact, it is a fixed background that does not let it move with the scroll axis, but the container containing the background is rolling, resulting in visual differences that look like a conversion scenario. (Don't be confused about this explanation ...)

The backgroud-attacthment attribute that defines the background scrolling mode in CSS is

Background-Attachment-- Define how the background image is moved along with the scroll Element

    • Value: Scroll | fixed | inherit

      • Scroll: default value. The background image will move along with the rest of the page.
      • Fixed: when the rest of the page is rolled, the background image will not move.
      • Inherit: specifies that the background-attachment attribute settings should be inherited from the parent element.
      • Initial Value: Scroll
      • Inheritance: No
      • Applicable to: All elements

Link to W3C: http://www.w3school.com.cn/css/pr_background-attachment.asp

Browser support:

Tested Chrome, opera, Safari, Firefox, ie7-8 is OK, so that IE6 can not ~

To use this attribute in IE6, You need to place background-Attachment: fixed in the body or HTML, that is, it is useless in other labels. The W3C above shows the effect because it is placed in the body.

This is my own demo. Click to download it.

Code:

 <!  Doctype html  >  <  Html  >      <  Head  >          <  Meta  Charset  = "UTF-8" >          <  Title  > Example of rolling Visual Difference </  Title  >          <  Style  >  *  {  Padding  : 0  ;  Margin  :  0  }  Body  {  Text-align  :  Center ;  Background-Attachment  :  Fixed  ;              }  # Main  {  Width  :  1280px ;  Margin  :  Auto  }  . Header  {  Background  :  # Fff  ; Padding  :  10px 0  }  . Bg-Attachment  {  Background  :  Url(6.jpg) center no-repeat  ; Box-shadow  :  0 7px 18px #000000 inset, 0-7px 18px #000000 inset  ;  -WebKit-box-shadow  :  0 7px 18px #000000 inset, 0-7px 18px #000000 inset  ;  -Moz-box-shadow  : 0 7px 18px #000000 inset, 0-7px 18px #000000 inset  ;  -O-box-shadow  :  0 7px 18px #000000 inset, 0-7px 18px #000000 inset  ;  -MS-box-shadow  :  0 7px 18px #000000 inset, 0-7px 18px #000000 inset  ; Background-Attachment  :  Fixed  ;              }  . Bg-attachment. Shadow  {  Width  :  80%  ; Height  :  700px  ;  Overflow  :  Hidden  ;  Margin  :  Auto ;              }  . Div2  {  Background  :  Url(qingz.jpg) center no-repeat  ;  Background-Attachment  :  Fixed ;              }          </  Style  >      </  Head  >      <  Body  >          <  Div  ID  = "Main"  >              < Div  Class  = "Header"  >                  <  IMG  SRC  = "5.jpg"  >              </  Div  >              <  Div  Class  = "BG-attachment"  >                 <  Div  Class  = "Shadow"  > </  Div  >              </  Div  >              <  Div  Class  = "Header"  >                  <  IMG SRC  = "Qi.jpg"  >              </  Div  >              <  Div  Class  = "BG-attachment div2"  >                  <  Div  Class  = "Shadow"  > </  Div >              </  Div  >          </  Div  >      </  Body  >  </  Html  > 

With more than 60 superb parallax scroll effect site design appreciation: http://www.qianduan.net/60-stunning-parallax-scrolling-effect-website-design.html

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.