Is there a way to scroll a background image until the end pixel and then go backwards to the beginning of the image, repeating this sequence continuously?
Currently, I have a code that scrolls the background image continuously in one direction. How can I modify it to achieve the desired effect?
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() {
// scroll by 1 pixel at a time
current -= 1;
// move the background using background-position css properties
$('body').css("backgroundPosition", (direction == 'h') ? current + "px 0" : "0 " + current + "px");
}
//Calls the scrolling function repeatedly
setInterval(bgscroll, scrollSpeed);