JQuery background layer scrolling instance code

Source: Internet
Author: User

As we need to work on our own, we hope that the background layer of an image album will scroll, but the above layer will not scroll. Then we will find an example of scrolling Based on the jQuery background layer. we will share it with you below.

Jquery code

The Code is as follows: Copy code

<Script type = "text/javascript" charset = "UTF-8">
Var scrollSpeed = 100; // speed (MS)
Var step = 1; // move 1 pixel each time
Var current = 0; // The current pixel row
Var imageWidth = 2247; // The width of the scroll chart.
Var headerWidth = 1280; // container width
// Start of the loop
Var restartPosition =-(imageWidth-headerWidth );
Function scrollBg (){
// Go to next pixel row.
Current-= step;
// If at the end of the image, then go to the top.
If (current = restartPosition) {current = 0 ;}
// Container IDClass
Certificate ('{header'}.css ("background-position", current + "px 0 ");}
// Repeated scrolling
Var init = setInterval ("scrollBg ()", scrollSpeed );
</Script>

The yellow color is the container ID or class. Put the above js near the background rolling container, and I have translated a few comments, there are a few more words out of my English scope, so I will not be moved.

Css code

The Code is as follows: Copy code

# Header {height: 180px; background: # 8EC1DA url(bg-clouds.png) repeat-y scroll left top; text-align: center ;}

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.