正如你所看到的......它最终会重复,但在一个完整的黑色背景循环之后。我想找到一种方法来制作它,以便在实际图像通过的第二秒,图像的开头就在末尾连接,因此您在滚动时看不到黑色。有任何想法吗?
HTML
<body>
<div id="wrapper">
<div id="header">
</div>
</div>
</body>
CSS
/* Give the header a height and a background image */
#header{
height:150px;
background: #000 url(Logo.jpg) repeat-y scroll left top;
text-align:center;
}
JS
var scrollSpeed = 50; // Speed in milliseconds
var step = 1; // How many pixels to move per step
var current = 0; // The current pixel row
var imageHeight = 4300; // Background image height
var headerHeight = 300; // How tall the header is.
//The pixel row where to start a new loop
var restartPosition = -(imageHeight - headerHeight);
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;
}
//Set the CSS of the header.
$('#header').css("background-position",current +"px 1");
}
//Calls the scrolling function repeatedly
var init = setInterval("scrollBg()", scrollSpeed);