一段JS代码,原来是滚动的。现在不动了。谁能给瞧瞧什么原因。
<!--<divclass="r_t_ad"><scriptsrc="/d/js/acmsd/thea2.js"></script></div>--><divclass=...
<!-- <div class="r_t_ad">
<script src="/d/js/acmsd/thea2.js"></script>
</div> -->
<div class="k_x">
<div style=" width:17px; float:left;"><img src="[!--news.url--]skin/default/images/laba.gif" width="17" height="24" /></div>
<div id="Mar" style=" float:left; overflow:hidden; width:260px;" >
<div id="inMar" style="float: left;width: 3500px;">
<div id="Mar1" style="float:left;">
<ul>
[ecmsinfo]66,10,40,0,12,2,0,'firsttitle=6'[/ecmsinfo]
</ul>
</div>
<!--滚动JS开始-->
<script language="javascript" type="text/javascript">
var speed = 25;
var div = document.getElementById("Mar");
var div1 = document.getElementById("Mar1");
div2.innerHTML = div1.innerHTML;
function Marquee() {
//向右滚动
//if (div.scrollLeft <= 0)
//div.scrollLeft += div2.offsetWidth
//else {
//div.scrollLeft--
//}
//向左滚动
if (div2.offsetWidth - div.scrollLeft <= 0)
div.scrollLeft -= div1.offsetWidth
else {
div.scrollLeft++;
}
}
var MyMarquee = setInterval(Marquee, speed);
div.onmouseover = function() { clearInterval(MyMarquee) };
div.onmouseout = function() { MyMarquee = setInterval(Marquee, speed) };
</script>
<!--滚动JS结束--> 展开
<script src="/d/js/acmsd/thea2.js"></script>
</div> -->
<div class="k_x">
<div style=" width:17px; float:left;"><img src="[!--news.url--]skin/default/images/laba.gif" width="17" height="24" /></div>
<div id="Mar" style=" float:left; overflow:hidden; width:260px;" >
<div id="inMar" style="float: left;width: 3500px;">
<div id="Mar1" style="float:left;">
<ul>
[ecmsinfo]66,10,40,0,12,2,0,'firsttitle=6'[/ecmsinfo]
</ul>
</div>
<!--滚动JS开始-->
<script language="javascript" type="text/javascript">
var speed = 25;
var div = document.getElementById("Mar");
var div1 = document.getElementById("Mar1");
div2.innerHTML = div1.innerHTML;
function Marquee() {
//向右滚动
//if (div.scrollLeft <= 0)
//div.scrollLeft += div2.offsetWidth
//else {
//div.scrollLeft--
//}
//向左滚动
if (div2.offsetWidth - div.scrollLeft <= 0)
div.scrollLeft -= div1.offsetWidth
else {
div.scrollLeft++;
}
}
var MyMarquee = setInterval(Marquee, speed);
div.onmouseover = function() { clearInterval(MyMarquee) };
div.onmouseout = function() { MyMarquee = setInterval(Marquee, speed) };
</script>
<!--滚动JS结束--> 展开
展开全部
变量div2没有定义
添加下面一行就好:
var div2 = document.getElementById("inMar");
<script language="javascript" type="text/javascript">
var speed = 25;
var div = document.getElementById("Mar");
var div1 = document.getElementById("Mar1");
var div2 = document.getElementById("inMar");
div2.innerHTML = div1.innerHTML;
function Marquee() {
//向右滚动
//if (div.scrollLeft <= 0)
//div.scrollLeft += div2.offsetWidth
//else {
//div.scrollLeft--
//}
//向左滚动
if (div2.offsetWidth - div.scrollLeft <= 0)
div.scrollLeft -= div1.offsetWidth
else {
div.scrollLeft++;
}
}
var MyMarquee = setInterval(Marquee, speed);
div.onmouseover = function() { clearInterval(MyMarquee) };
div.onmouseout = function() { MyMarquee = setInterval(Marquee, speed) };
</script>
添加下面一行就好:
var div2 = document.getElementById("inMar");
<script language="javascript" type="text/javascript">
var speed = 25;
var div = document.getElementById("Mar");
var div1 = document.getElementById("Mar1");
var div2 = document.getElementById("inMar");
div2.innerHTML = div1.innerHTML;
function Marquee() {
//向右滚动
//if (div.scrollLeft <= 0)
//div.scrollLeft += div2.offsetWidth
//else {
//div.scrollLeft--
//}
//向左滚动
if (div2.offsetWidth - div.scrollLeft <= 0)
div.scrollLeft -= div1.offsetWidth
else {
div.scrollLeft++;
}
}
var MyMarquee = setInterval(Marquee, speed);
div.onmouseover = function() { clearInterval(MyMarquee) };
div.onmouseout = function() { MyMarquee = setInterval(Marquee, speed) };
</script>
追问
我问一下。现在这个问题已经解决了。
我前后对比了一下。只变了一个数值
width:5000px
真的不明白。
追答
div.scrollLeft的值不能超过div.scrollWidth-div.width
div.scrollWidth的值为:
中的width:3500.
div.width的值为:
div.scrollLeft的最大值=3500-260=3240
如果div.scrollWidth= div2.offsetWidth + div.width
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询