产品滚动图片滚动方向问题。这个产品图片滚动代码默认是往左滚动的,怎么改成往右呢。

var dir=1//每步移动像素,大=快var speed=30//循环周期(毫秒)大=慢demo2.innerHTML=demo1.innerHTMLfunction Marquee(){//正常移动 //alert(demo2.offsetWidth+"\n"+demo.scrollLeft) if (dir>0 && (demo2.offsetWidth-demo.scrollLeft)<=0) demo.scrollLeft=0 if (dir<0 &&(demo.scrollLeft<=0)) demo.scrollLeft=demo2.offsetWidth demo.scrollLeft+=dir demo.onmouseover=function() {clearInterval(MyMar)}//暂停移动 demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}//继续移动}function r_right(){if (dir=1)dir=-1}//换向右移function r_left(){if (dir=-1)dir=1}//换向左移var MyMar=setInterval(Marquee,speed)
2026-12-04 13:28:21
推荐回答(2个)
回答1:

var dir=1//每步移动像素,大=快
var speed=30//循环周期(毫秒)大=慢
demo2.innerHTML=demo1.innerHTML
function Marquee(){//正常移动
//alert(demo2.offsetWidth+"\n"+demo.scrollRight)
if (dir>0 && (demo2.offsetWidth-demo.scrollRight)<=0) demo.scrollRight=0
if (dir<0 &&(demo.scrollright<=0)) demo.scrollRight=demo2.offsetWidth
demo.scrollRight+=dir

demo.onmouseover=function() {clearInterval(MyMar)}//暂停移动
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}//继续移动
}
function r_left(){if (dir=1)dir=-1}//换向左移
function r_right(){if (dir=-1)dir=1}//换向右移

你这个代码是自己写的,还是直接从原文件复制过来的?
上面明显是用CSS样式,所以要改,也得从CSS里面改,我修改了一下,你可以看看

var MyMar=setInterval(Marquee,speed)

回答2:

function r_right(){if (dir=1)dir=-1}//换向右移
function r_left(){if (dir=-1)dir=1}//换向左移