zoukankan      html  css  js  c++  java
  • 鼠标离开方向检测

    直接看效果点这里

    <html>
    <head>鼠标离开方向检测</head>
    <body>
    <div id="msg">鼠标放到框上,然后移开。</div>
    <div id="wrap" style="200px; height: 100px; line-height:30px; margin: 100px auto; text-align: center; border: 1px solid #99bbe8;">↖↑↗<br/>← →<br/>↙↓↘</div>
    <script src="http://common.cnblogs.com/script/jquery.js"></script>
    <script>
    $("#wrap").on("mouseenter mouseleave",function(e) {
        var w = $(this).width();
        var h = $(this).height();
        var x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
        var y = (e.pageY - this.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
        var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 45) + 3) % 8;
        var dirName = ['右下', '', '左下', '', '左上', '', '右上', ''];
        if(e.type == 'mouseenter'){
            $("#msg").html(dirName[direction]+'-进入');
        }else{
            $('#msg').html(dirName[direction]+'-离开');
        }
    });
    </script>
    </body>
    </html>
  • 相关阅读:
    个人总结11
    进度条4,5
    对vivo自带输入法的评价
    个人总结10
    hdu5589Tree
    HDU5213 Lucky
    2018icpcShenYangE
    bzoj3683: Falsita
    cf396C. On Changing Tree
    cf600E. Lomsat gelral
  • 原文地址:https://www.cnblogs.com/jununx/p/4472894.html
Copyright © 2011-2022 走看看