zoukankan      html  css  js  c++  java
  • js实现右侧的分享效果

    就是当鼠标移到上面的时候,他会出现,鼠标移出就消失。

    nmouseover和nmouseout就能实现

    <style>
    *{padding:0;margin:0;}
        #s1{width:200px ;
                background:red;
                 height:200px;
                position:absolute;
                top:50px;
                left:-200px;
                cursor:pointer;}
        #s1 span
    {display:block;height:80px;width:20px;left:200px;background:blue;position:absolute;left:200px;top:50px;}
    }
    </style>
    
    <body>
    <div id="s1">
        <span>分享到</span>
    </div>    
    </body>                                        

    js代码如下

    <script>
        window.onload=function()
        {
           var div1=document.getElementById("s1");  
           var span1=s1.getElementsByTagName("span")[0];   
    
           div1.onmouseover=function()
           {
            startMove(0);
           }
           div1.onmouseout=function()
           {
            startMove(-200);
           }
       };
        var timer=null;
        function startMove(ti)
        {
             var div1=document.getElementById("s1");
             clearInterval(timer);
             timer=setInterval(function()
                {
                    var speed=null;
                    if (div1.offsetLeft>ti)  //先判断他的速度是正的还是负的,如果offsetLeft大于0,速度为负
                    {
                        speed=-10;
                    }
                    else   //否则速度为正,显示div要出来
                    {
                        speed=10;
                    }
    
                    if (div1.offsetLeft==ti)  //相等,停止运动
                    {
                        clearInterval(timer);
                    }
                    else  //不相等,做匀速运动
                    {
                        div1.style.left=div1.offsetLeft+speed+'px';
                    }
                },30);
        }
    </script>

    其实特别简单,只要收敲敲就会,

  • 相关阅读:
    Jmeter断言设置
    jmeter设置自动启动时间
    jmeter用命令行运行jmx脚本
    jmeter多用户并发压力测试(导入文件)
    Fiddler导出接口抓包数据
    postman和postwoman
    UVa10561
    UVa11859
    Ferguson游戏
    UVa11916
  • 原文地址:https://www.cnblogs.com/biyongyao/p/5850362.html
Copyright © 2011-2022 走看看