javascript 向上滾動公告(原創)

來源:互聯網
上載者:User

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>無標題頁</title>
</head>
<body>

<div style="width:400px;height:23px;overflow:hidden;background-color:red">
<div id="noticev2" style="white-space:nowrap;" onmouseover="javascript:isMove=false" onmouseout="javascript:isMove=true">
<a target="_blank" href="http://zhidao.baidu.com/question/42884976.html?fr=qrl">什麼叫javascript</a><br>
<a target="_blank" href="http://zhidao.baidu.com/question/41573038.html?fr=qrl">JavaScript 對錶單的驗證問題</a><br>
<a target="_blank" href="http://zhidao.baidu.com/question/37308454.html?fr=qrl">
JavaScript中event對象是做什麼用的?</a><br>
<a target="_blank" href="http://zhidao.baidu.com/question/35464099.html?fr=qrl">
看看我這段JAVASCRIPT哪出問題了,為什麼運行不了呢</a><br>
<a target="_blank" href="http://zhidao.baidu.com/question/34079794.html?fr=qrl">
JS表單驗證 如何限制使用者密碼只能輸入小寫字母底線...</a>

</div>
</div>
<script>
var tID;
var tn;
var nStopTime=3000
var nSpeed=50
var isMove=true;
var nHeight=20;
var nS=0
var nNewsCount=0

function moveT(n)
{
    clearTimeout(tID)
    var noticev2= document.getElementById("noticev2")
    if(n)
    {
        noticev2.style.lineHeight=nHeight+"px";
        var theText=noticev2.innerHTML.toLowerCase();   
        nNewsCount=theText.split("<br>").length     
        noticev2.innerHTML+="<br>"+noticev2.innerHTML;
        tn=nHeight;
    }
    nS=nSpeed;
    if(isMove)
    {
        noticev2.style.marginTop=tn+"px";
        if((tn-2)%nHeight==0)
        {
            nS=nSpeed+nStopTime;
        }
           
        tn--;
        if(Math.abs(tn)==(nNewsCount*nHeight*2-nHeight))
        tn=(nNewsCount-1)*nHeight*-1;
    }
   
    tID=setTimeout("moveT()",nS);
}

moveT(1);
</script>


</body>
</html>
大意如此,具體使用時需要注意行高與nHeight的關係!!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.