zoukankan      html  css  js  c++  java
  • 文字自动自左向右滚动的js代码

    重要的一点,就是scrollLeft一直在变化。对象一直在移动,参照物没有动。

    代码:

    css:

    #div1{display:black;width:110px;height:50px;line-height:50px;white-space:nowrap;overflow:hidden;background-color:#a2a2a2;margin:15px;padding:5px 15px;}
    span{display:inline-block;color:#fff;padding-right:20px;}

    html:

    <!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" xml:lang="en">
    <head>
    <meta charset="utf-8"/>
    <title>mq</title>
     </head>
     <body>
        <div id="div1">
            <span id="span1">天天币专享项</span><span id="span2"></span>
        </div><span id="span1">天天币专享项目A</span>
     </body>
    </html>

    js:

    var div,span,span2,i,timer;
            function init(){
                setInterval(ttb,50);
            }
            function ttb(){
                div = getId('div1');
                span = getId('span1');
                span2 = getId('span2');
                
                span2.innerHTML = span.innerHTML;
                if(span.offsetWidth <= div.scrollLeft){
                    div.scrollLeft -= span.offsetWidth;
                    
                }
                else {
                    div.scrollLeft++;
                }
                
            }
            function getId(Id){
                return document.getElementById(Id);
            }
            window.onload = init();
  • 相关阅读:
    Java.util.concurrent包学习(一) BlockingQueue接口
    [转载]最牛B的编码套路
    思考人生
    非奇异矩阵的零度互补法则
    Hopfield 网络(下)
    Hopfield 网络(上)
    矩阵的相似性与对角化
    左右特征向量
    特征多项式、代数重数与几何重数
    特征值和特征向量
  • 原文地址:https://www.cnblogs.com/hao5599/p/4567825.html
Copyright © 2011-2022 走看看