当前位置: 代码迷 >> ASP.NET >> 为什么不会滚动,一段JS滚动代码解决方案
  详细解决方案

为什么不会滚动,一段JS滚动代码解决方案

热度:5398   发布时间:2013-02-25 00:00:00.0
为什么不会滚动,一段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&gt;&gt;</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 code
<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>
  相关解决方案