zoukankan      html  css  js  c++  java
  • 鼠标悬停(鼠标悬停一段时间后触发事件)一段时间后触发事件,鼠标停留超过N秒,才触发

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        var mytimer = null;
       
        function beginEvent(){     
          //window.setTimeout("alert('Hello, world')", 1000);
          mytimer = window.setTimeout("myfunc('123','456')", 3000);        
        }
    
        
    
    function cancelEvent() {
      clearTimeout(mytimer);      
      mytimer = -1;
    }
    
    function myfunc(t1,t2) {
                    alert(t1+" ,"+t2);
            if (mytimer == -1) return;
            var d = document.getElementById("div1");
            d.innerText = new Date();
            clearTimeout(mytimer);
            mytimer = null;
    }
    </script>
    </head>
    <body>
      <br/>
      <br/>
      <div id="div1" style="position: absolute; top: 100px; left: 100px;  100px; height: 100px; border: 1px solid black;" onmouseover="beginEvent()" onmouseout="cancelEvent()"></div>
    </body>
    </html>
    //鼠标放上去0.5秒后执行preview方法,鼠标移出就清除timeout
    $('body').on('mouseover','.ac_over',function() {
            timer = setTimeout(function(){
                preview($('.ac_over').attr('data-id'));
            },500);
        });
        $('body').on('mouseout','.ac_over',function() {
            clearTimeout(timer);
        });
  • 相关阅读:
    设计模式的原则
    命令模式
    访问者模式
    策略模式
    外观模式
    组合模式
    原型模式
    合并有序数组
    判断二叉树是否对称
    中序遍历二叉树
  • 原文地址:https://www.cnblogs.com/elves/p/3884928.html
Copyright © 2011-2022 走看看