非常好用的marquee滚动闭合JS代码,内容自动向上滚屏并停顿

发布时间:2009年04月14日      浏览次数:728 次
<div id="adsfar">
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bordercolordark="#ffffff">
<tr>
<td height="25" bgcolor="#FFFFFF">1</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">2</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">3</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">4</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">5</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">6</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">7</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">8</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">9</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">10</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">11</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">12</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">13</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">14</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">15</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">16</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">17</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">18</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">19</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">20</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">21</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">22</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">23</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">24</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">25</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">26</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">27</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">28</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">29</td>
</tr>
<tr>
<td height="25" bgcolor="#FFFFFF">30</td>
</tr>
</table>
</div>
<script type="text/javascript">
marque("adsfar", 200, 125, 20); //参数说明:内容区ID、区域宽度、区域高度、滚动速度(毫秒)
var scrollElem;
var stopscroll;
var stoptime;
var preTop;
var leftElem;
var currentTop;
var marqueesHeight;
function marque(id, width, height, sudu){
      try{
            marqueesHeight = height;
            stopscroll = false;
            scrollElem = document.getElementById(id);
            with(scrollElem){
                  style.width = width;
                  style.height = marqueesHeight;
                  style.overflow = 'hidden';
                  noWrap = true;
            }
            scrollElem.onmouseover = new Function('stopscroll = true');
            scrollElem.onmouseout = new Function('stopscroll = false');
            preTop = 0;
            currentTop = 0;
            stoptime = 0;
            leftElem = document.getElementById(id);
            scrollElem.appendChild(leftElem.cloneNode(true));
            
            init_srolltext(sudu);
      }catch(e) {}
}
function init_srolltext(sudu){
      scrollElem.scrollTop = 0;
      setInterval('scrollUp()', sudu);
}
function scrollUp(){
      if(stopscroll) return;
      currentTop += 1;
      if(currentTop == marqueesHeight+1) {
            stoptime += 1;
            currentTop -= 1;
            if(stoptime == (marqueesHeight)*1) {//停顿时间
                  currentTop = 0;
                  stoptime = 0;
            }
      }else{
            preTop = scrollElem.scrollTop;
            scrollElem.scrollTop += 1;
            if(preTop == scrollElem.scrollTop){
                  scrollElem.scrollTop = marqueesHeight;
                  scrollElem.scrollTop += 1;
            }
      }
}
</script>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!