html - jQuery image sliding up instead of sliding right -
basically code making image slide when want slide right. what's wrong it?
html
<div id="wrapper"> <div id="header"> </div> </div>
js
var scrollspeed = 70; // speed in milliseconds var step = 1; // how many pixels move per step var current = 0; // current pixel row var imageheight = 4300; // background image height var headerheight = 300; // how tall header is. //the pixel row start new loop var restartposition = -(imageheight - headerheight); function scrollbg(){ //go next pixel row. current -= step; //if @ end of image, go top. if (current == restartposition){ current = 0; } //set css of header. $('#header').css("background-position","0 "+current+"px"); } //calls scrolling function repeatedly var init = setinterval("scrollbg()", scrollspeed);
here code: http://pastebin.com/9fpvsbxm
you need increment value
function scrollbg(){ //go next pixel row. current += step; //increment instead of decrement //if @ end of image, go top. if (current == restartposition){ current = 0; } //set css of header. $('#header').css("background-position",current +"px 0"); // parameters right top not top right }
demo: fiddle
Comments
Post a Comment