我要滾動的背景圖像,直到最後像素,然後倒退到圖像的開始。我想不斷重複這個順序。滾動背景圖像
我有一個代碼,但它在一個方向上連續滾動的背景圖像。
我怎麼能更改此代碼工作,我想要什麼?
CSS:
body{margin:0; border:0; background:url(ejemplo3.jpg) repeat-x;}
HTML:
<body></body>
JQuery的:
var scrollSpeed = 50;
// set the default position
var current = 0;
// set the direction
var direction = 'h';
function bgscroll() {
// 1 pixel row at a time
current -= 1;
// move the background with backgrond-position css properties
$('body').css("backgroundPosition", (direction == 'h') ? current + "px 0" : "0 " + current + "px");
}
//Calls the scrolling function repeatedly
setInterval(bgscroll, scrollSpeed);
非常感謝你Ashok!你的代碼完美工作。 – user3375954
嗨,我有一個代碼中的問題,當我有一個1024或1480的屏幕分辨率的背景圖像沒有到達其最終像素(水平)或超過其最終像素(水平),我怎麼能解決呢? 下面是一個例子在線:http://www.ideas-web.net63.net/prueba/prueba.html – user3375954