zoukankan      html  css  js  c++  java
  • js动画实现侧边栏分享

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>分享</title>
    <style>
    body,div,span{
        margin:0;
        padding:0;
        }
    .div{
        background:red;
        width:200px;
        height:200px;
        position:relative;
        left:-200px;
        top:10px;
        
        }
    .a{
        padding:2px;
        width:20px;
        height:50px;
        position:absolute;
        left:200px;
        top:20px;
        background:blue;
        color:white;
        text-decoration:none;
        }
    </style>
    <script>
    window.onload = function (){
        var div = document.getElementById('div');
        div.onmouseover = function (){
            display(10,0);
            }
        div.onmouseout = function (){
            display(-10,-200);
            }
        }
        var stop = null;
    function display(speed, targetLeft){
        clearInterval(stop);
        var div = document.getElementById('div');
        stop = setInterval(function(){
            if(div.offsetLeft == targetLeft){
                clearInterval(stop);
            }
            else{
                div.style.left = div.offsetLeft + speed + 'px';
                }
            }, 30);
        }
    </script>
    </head>
    
    <body>
    <div class="div" id="div">
    <a href="#" class="a" id="a">分享</a>
    </div>
    
    </body>
    </html>

    动画总结:写js函数时,如果两个函数差不多,可以把相同的地方提出来当参数穿进去。对于计时器要想到清空它。

    努力吧,为了媳妇儿,为了家。。。
  • 相关阅读:
    P2319 [HNOI2006]超级英雄
    P4302 [SCOI2003]字符串折叠
    P1122 最大子树和
    HDU——2089 不要62
    P4555 最长双回文串
    P1463 [HAOI2007]反素数
    P2412 查单词
    P2787 语文1(chin1)- 理理思维
    P3078 [USACO13MAR]扑克牌型Poker Hands
    ubuntu中desktop与alternate版本的区别(转载)
  • 原文地址:https://www.cnblogs.com/jlj9520/p/5083749.html
Copyright © 2011-2022 走看看