JSは文字の左右スクロールを実現

1379 ワード




    
    

<style>
    p{position: absolute;left: 125px; top: 100px;}
</style>

<script>
    var tag = 0;//  ,                ,             ,     setTimeOut      0,         
    //    
    function moveWord(){
        var resource = document.getElementById("word");
        var x = parseInt(window.getComputedStyle(resource,null).left);//        x   ,    int  
        var tx = 500;//    
        var rx = 125;//         
        if(x < tx && tag == 0)//    
        {
            x++;
            if(x == tx)//         ,     1
                tag = 1;
        }
        if(x> rx && tag == 1)//    
        {
            x--;
            if(x == rx)//         ,     0
                tag = 0;
        }
        resource.style.left = x + "px";//     x   
        t = setTimeout("moveWord()",10);//    ,10       ,       

    }
    window.onload =moveWord;
</script>

<p id="word">      </p>

</code></pre> 
  <p><br/></p> 
  <p>      x   ,         ,             ,    </p> 
  <pre><code>var x = parseInt(resource.style.left);</code></pre> 
  <br/> 
 </div> 
</div>
                            </div>
                        </div>