zoukankan      html  css  js  c++  java
  • JS:“分享到”之类的悬浮框的运动原理(代码)

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title>只传一个参数</title>
            <style type="text/css">
                .div {
                    width: 100px;
                    height: 100px;
                    background-color: chartreuse;
                    margin-top: 50px;
                    position: absolute;
                    left: -100px;
                    top: 0;
                    cursor: pointer;
                }
                .div span{
                    display: block;
                    width: 20px;
                    height: 50px;
                    position: absolute;
                    right: -20px;
                    top: 50%;
                    margin-top: -25px;
                    background-color: coral;
                    font-size: 10px;
                    padding: 5px;
                    -webkit-box-sizing: border-box;
                    box-sizing: border-box;
                }
            </style>
            <script type="text/javascript">
            window.onload = function(){
                var oDiv = document.getElementById('div');
                oDiv.onmouseover = function(){
                    start(0);
                };
                oDiv.onmouseout = function(){
                    start(-100);
                };
            };
                var timer = null;
                //功能一抹一样的函数,参数越少越好。
                function start(iTarget) {
                    var oDiv = document.getElementById('div');
                    clearInterval(timer);
                    timer = setInterval(function() {
                        var speed = 0;
                        if(oDiv.offsetLeft>iTarget){
                            speed = -10;
                        }else{
                            speed = 10;
                        };
                        if(oDiv.offsetLeft == iTarget) {
                            clearInterval(timer);
                        }
                        else{
                            oDiv.style.left = oDiv.offsetLeft + speed + 'px';
                        }
                        
                    }, 30)
                };
            </script>
        </head>
    
        <body>
            <div class="div" id="div"><span>分享到</span></div>
        </body>
    
    </html>

    学习路径与来源:智能社的开发教程:https://ke.qq.com/webcourse/index.html#course_id=152997&term_id=100174752&taid=766913655494053&vid=v14127nxshc

  • 相关阅读:
    TLB原理
    64寄存器位查看器
    araxis Merge
    start_KERNEL
    python 动态支持方案
    https://wenku.baidu.com/view/6142875b804d2b160b4ec06b.html 编译原理课件
    有无符号数的区别
    vim工具的路径
    edraw软件破解密钥已经上传,见文件目录
    https://tieba.baidu.com/p/2248070024
  • 原文地址:https://www.cnblogs.com/padding1015/p/6403092.html
Copyright © 2011-2022 走看看