1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

谁有这段js代码能提供一下吗?

本帖由 kamsang2006-04-12 发布。版面名称:前端开发

  1. kamsang

    kamsang New Member

    注册:
    2005-10-05
    帖子:
    9,080
    赞:
    58
    类似于http://www.chinaui.com/, 里面滚动字幕的js代码... 但是他自身网站的js代码有些问题... 不知道有没有人有这段完整的js代码没? 希望能共享一下.....
     
  2. shangjay

    shangjay New Member

    注册:
    2006-01-13
    帖子:
    3,530
    赞:
    15
    我看看
     
  3. gojorare

    gojorare New Member

    注册:
    2006-03-05
    帖子:
    87
    赞:
    0
    HTML:
    var scrollerwidth=360
    var scrollerheight=20
    var scrollerbgcolor=''
    var messages=new Array()
    //信息内容
    messages[0]=" 第零句"
    messages[1]=" 第一句 "
    messages[2]=" 第二句"
    messages[3]=" 第三句"
    messages[4]=" 第四句";
    messages[5]=" 第五句";
    messages[6]=" 第六句";
    
    if (messages.length>1)
     i=2;
    else
     i=0;
    function move1(whichlayer){
    tlayer=eval(whichlayer)
    if (tlayer.top>0&&tlayer.top<=5){
    tlayer.top=0
    setTimeout("move1(tlayer)",3000)
    setTimeout("move2(document.main.document.second)",3000)
    return
    }
    if (tlayer.top>=tlayer.document.height*-1){
    tlayer.top-=5
    setTimeout("move1(tlayer)",100)
    }
    else{
    tlayer.top=scrollerheight
    tlayer.document.write(messages[i])
    tlayer.document.close()
    if (i==messages.length-1)
    i=0
    else
    i++
    }
    }
    function move2(whichlayer){
    tlayer2=eval(whichlayer)
    if (tlayer2.top>0&&tlayer2.top<=5){
    tlayer2.top=0
    setTimeout("move2(tlayer2)",3000)
    setTimeout("move1(document.main.document.first)",3000)
    return
    }
    if (tlayer2.top>=tlayer2.document.height*-1){
    tlayer2.top-=5
    setTimeout("move2(tlayer2)",100)
    }
    else{
    tlayer2.top=scrollerheight
    tlayer2.document.write(messages[i])
    tlayer2.document.close()
    if (i==messages.length-1)
    i=0
    else
    i++
    }
    }
    function move3(whichdiv){
    tdiv=eval(whichdiv)
    if (tdiv.style.pixelTop>0&&tdiv.style.pixelTop<=5){
    tdiv.style.pixelTop=0
    setTimeout("move3(tdiv)",3000)
    setTimeout("move4(second2)",3000)
    return
    }
    if (tdiv.style.pixelTop>=tdiv.offsetHeight*-1){
    tdiv.style.pixelTop-=5
    setTimeout("move3(tdiv)",100)
    }
    else{
    tdiv.style.pixelTop=scrollerheight
    tdiv.innerHTML=messages[i]
    if (i==messages.length-1)
    i=0
    else
    i++
    }
    }
    function move4(whichdiv){
    tdiv2=eval(whichdiv)
    if (tdiv2.style.pixelTop>0&&tdiv2.style.pixelTop<=5){
    tdiv2.style.pixelTop=0
    setTimeout("move4(tdiv2)",3000)
    setTimeout("move3(first2)",3000)
    return
    }
    if (tdiv2.style.pixelTop>=tdiv2.offsetHeight*-1){
    tdiv2.style.pixelTop-=5
    setTimeout("move4(second2)",100)
    }
    else{
    tdiv2.style.pixelTop=scrollerheight
    tdiv2.innerHTML=messages[i]
    if (i==messages.length-1)
    i=0
    else
    i++
    }
    }
    function startscroll(){
    if (document.all){
    move3(first2)
    second2.style.top=scrollerheight
    }
    else if (document.layers){
    move1(document.main.document.first)
    document.main.document.second.top=scrollerheight+5
    document.main.document.second.visibility='show'
    }
    }
    window.onload=startscroll
    
    document.writeln('<span id="main2" 
    style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hiden;ba
    ckground-color:'+scrollerbgcolor+'">')
    document.writeln('<div 
    style="position:absolute;width:'+scrollerwidth+';height:'+scrollerheight+';clip:rect(0 
    '+scrollerwidth+' '+scrollerheight+' 0);left:0;top:2">')
    document.writeln('<div id="first2" 
    style="position:absolute;width:'+scrollerwidth+';left:0;top:2;">')
    document.write(messages[0])
    document.writeln('</div>')
    document.writeln('<div id="second2" 
    style="position:absolute;width:'+scrollerwidth+';left:0;top:2">')
    document.write(messages[1])
    document.writeln('</div>')
    
    我觉得这段挺好,我以前用过,没有什么问题,你看下
     
  4. 不学无术

    不学无术 Ulysses 的元神

    注册:
    2005-08-31
    帖子:
    16,714
    赞:
    39
    IE 下面没什么问题。

    HTML:
    <div>				
    <script language="JavaScript">
    document.ns = navigator.appName == "Microsoft Internet Explorer"
    function randomStr(str) {
    	var showId = Math.floor(Math.random()*4);
    	var tempStr = str[showId];
    	str[showId] = str[0];
    	str[0] = tempStr;
    }
    
    function showStr(str, textWidth, num) {
    	if(!document.ns) {
    	    document.write(str[0] + '<br/>')
    	}
    	else {
    		document.write('<table border=0 cellspacing=0 cellpadding=0>'
    		 + '<tr><td>'
    		 + '<div id="icefable1' + num + '">'
    		 + '<table width=' + textWidth + ' border=0 cellspacing=0 cellpadding=0>'
    		//+'<tr><td height=20>'+str[0]+'</td></tr>'
    		 + '<tr><td height=20>' + str[0] + '</td></tr>' + '<tr><td height=20>' + str[1] + '</td></tr>'+'<tr><td height=20>' + str[2] + '</td></tr>' + '<tr><td height=20>' + str[3] + '</td></tr>'
    		 + '</table>'
    		 + '</div>'
    		 + '<div id="icefable2' + num + '" style="position: absolute; z-index: 1; visibility: hidden"></div>'
    		 + '</td></tr>'
    		 + '</table>');
    	}
    }
    
    function init_srolltext(num) {
        countnum = 0
        marqueesHeight = 20;
        eval('stopscroll'+num+'=false;')
        eval('icefable1'+num+'.scrollTop=0;')
        rotatenum=0
        eval('icefable1'+num+'.style.width=0;')
        eval('icefable1'+num+'.style.height=marqueesHeight;')
        eval('icefable1'+num+'.style.overflowX="visible";')
        eval('icefable1'+num+'.style.overflowY="hidden";')
        eval('icefable1'+num+'.noWrap=true;')
        eval('icefable1'+num+'.onmouseover=new Function("stopscroll=true");')
        eval('icefable1'+num+'.onmouseout=new Function("stopscroll=false");')
        eval('preTop'+num+'=0; ')
        eval('currentTop'+num+'=0;')
        eval('stoptime'+num+'=0;')
        eval('icefable2'+num+'.innerHTML="";')
        eval('icefable2'+num+'.innerHTML+=icefable1'+num+'.innerHTML;')  
        eval('icefable1'+num+'.innerHTML=icefable2'+num+'.innerHTML+icefable2'+num+'.innerHTML;')  
        eval('setInterval("scrollUp'+num+'()",40);') 
    }
    
    function scrollUp1() {
      if(stopscroll1==true) return;
      currentTop1+=1;
      if(currentTop1==21){
      	stoptime1+=1;
      	currentTop1-=1;
      	if(stoptime1==80){
      		currentTop1=0;
      		stoptime1=0;
      	}
      }else{
    	  preTop1=icefable11.scrollTop;
    	  icefable11.scrollTop+=1;
    	  if(icefable11.scrollTop==78){
    	    preTop1=0; currentTop1=0; stoptime1=0;icefable11.scrollTop=0
    	  }
      }
    }
    
    var strArray1=new Array();
    //strArray1[0]='<a href=http://sina.allyes.com/main/adfclick?db=sina&bid=14447,35689,35717&cid=0,0,0&sid=35300&advid=1965&camid=6678&show=ignore&url=http://www.hongmaun.com.cn/web/wangfei/ target=_blank>11111</a>';
    strArray1[0]='<a href="mailto:info#chinaui.com">欢迎大家给我们提意见</a>';
    strArray1[1]='Blog频道正在测试中...';
    strArray1[2]='网站还有一些不尽如人意的Bug,我们正在完善中';
    strArray1[3]='<a href="http://www.mouce.cn/news/detail/20051028122323.html">ChinaUI v5 beta版发布</a>';
    randomStr(strArray1);
    showStr(strArray1, 300, 1);
    init_srolltext(1);
    </script>
    </div>
     
  5. kamsang

    kamsang New Member

    注册:
    2005-10-05
    帖子:
    9,080
    赞:
    58
     
  6. kamsang

    kamsang New Member

    注册:
    2005-10-05
    帖子:
    9,080
    赞:
    58
     
  7. 不学无术

    不学无术 Ulysses 的元神

    注册:
    2005-08-31
    帖子:
    16,714
    赞:
    39
    终于找到问题了。

    preTop1=0; currentTop1=0; stoptime1=0;icefable11.scrollTop=0

    上面这行修改为

    preTop1=0; currentTop1=20; stoptime1=0;icefable11.scrollTop=0

    试试看?不过他的代码编写不合理,不容易扩展。

    :lol:
     
  8. kamsang

    kamsang New Member

    注册:
    2005-10-05
    帖子:
    9,080
    赞:
    58


    谢谢不学兄了... 这个问题解决了好看多了!

    它这个代码是不容易扩展, 刚才准备加一条就不行! :lol: