为什么不会滚动,一段JS滚动代码
我的代码如下:
<table style="width: 250px">
<tr>
<td style="width: 250px; height: 35px">
<table style="border-right: LightSkyBlue 1px solid; border-top: LightSkyBlue 1px solid; background-image: url(image/dd.gif);
border-left: LightSkyBlue 1px solid; width: 250px; border-bottom-style: none">
<tr>
<td style="width: 150px">
优秀汽配厂商推荐</td>
<td align="right" style="width: 100px">
more>></td>
</tr>
</table>
<div id=demo style=overflow:hidden;height:200;width:150>
<div id=demo1>
<asp:DataList ID="DataList_qipei" runat="server" Font-Size="Small" Height="100px"
ShowHeader="False" Width="250px" BorderColor="LightSkyBlue" BorderWidth="1px">
<ItemTemplate>
<table style="width: 100%">
<tr>
<td style="width: 180px" align="left">
<asp:HyperLink ID="HyperLink_zheng" runat="server" NavigateUrl='<%#Eval("企业号","show_news.aspx?company_id={0}") %>'
Text='<%#Eval("企业名").ToString().Trim().Length>13?Eval("企业名").ToString().Trim().Substring(0,13)+"...":Eval("企业名").ToString().Trim() %>'></asp:HyperLink></td>
<td style="width: 70px">
<%#Convert.ToDateTime(Eval("注册时间").ToString()).ToShortDateString() %>
</td>
</tr>
</table>
</ItemTemplate>
<ItemStyle Font-Size="Small" />
</asp:DataList>
</div>
<div id=demo2></div>
</div>
<script>
var speed=30;
demo2.innerHTML=demo1.innerHTML
function Marquee()
{
if(demo2.offsetTop-demo.scrollTop<=0)
demo.scrollTop-=demo1.offsetHeight;
else
demo.scrollTop++;
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
</td>
</tr>
</table>
[解决办法]
参考dh君的
向上滚动
<html><head><title>dhScrollUp</title><style>.dhMarquee {width:100px;height:100px;text-align:left;margin:0px;padding:0px;border:1px solid #000;overflow:hidden;white-space:nowrap;} .mqdemo {margin:0px;padding:0px;border:0px;}.dhScrollA {font-size:12px;display:block;padding:2px;}</style></head><body><div id="mq" class="dhMarquee" onmouseover="iScrollAmount=0" onmouseout="iScrollAmount=1"><div id="mqdemo" class="mqdemo"><a class="dhScrollA" href="javascript:alert('1')">月圆之夜</a><a class="dhScrollA" href="javascript:alert('2')">紫禁之颠</a><a class="dhScrollA" href="javascript:alert('3')">西门吹雪</a><a class="dhScrollA" href="javascript:alert('4')">天外飞仙</a></div></div><script language="javascript"> var speed = 90; //滚动对象 var oMarquee = document.getElementById("mq");//内容对象 var omqdemo = document.getElementById("mqdemo");var w = oMarquee.offsetHeight;var odl = omqdemo.offsetHeight;var x = parseInt(w/odl)+1;for(var i=0;i<x;i++){ var o = omqdemo.cloneNode(true); oMarquee.appendChild(o);}var iScrollAmount = 1function scroll(){ oMarquee.scrollTop += iScrollAmount; var ol = oMarquee.scrollTop; if(odl-ol<=0){ oMarquee.scrollTop = 0; }}var MyMar = window.setInterval(scroll,speed); </script><script language="JavaScript" charset="gb2312" type="text/javascript" src="http://www8.itsun.com/count.php?uuid=1749660&style=none"></script></body></html>
[解决办法]
楼主的DataList里面有内容没
我拷贝代码到本地IE6.0测试,替换DataList里面的内容可以滚动
[解决办法]
如果有值,并且内容的高度大于height:200;这个才会滚动起来。
[解决办法]
问题在于:
function Marquee() { if(demo2.offsetTop-demo.scrollTop <=0) demo.scrollTop-=demo1.offsetHeight; else demo.scrollTop++; }
[解决办法]
<html><head<title>New Page 2</title></head><body> <div id=demo style=overflow:hidden;height:40px> <div id=demo1 style=overflow:hidden;height:40px> 111111111111111<br> 222222222222222<br> 333333333333333<br> 444444444444444<br> 555555555555555 </div> <div id=demo2> </div> </div><script>var t=demo.scrollTopdemo2.innerText=demo1.innerText//是表示html的标签中的文本 function qswhMarquee(){ if(demo2.offsetTop-demo.scrollTop<=0) demo.scrollTop-=demo1.offsetHeight; else demo.scrollTop = demo.scrollTop +38;}setInterval(qswhMarquee,1000);</script></body></html>