zoukankan      html  css  js  c++  java
  • 判断鼠标从哪个方向进入--jQuery

    转载自:http://sentsin.com/web/112.html

    $("#wrap").bind("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) / 90) + 3) % 4; //direction的值为“0,1,2,3”分别对应着“上,右,下,左”
               var eventType = e.type;
               var dirName = new Array('上方','右侧','下方','左侧');
               if(e.type == 'mouseenter'){
                  $("#result").html(dirName[direction]+'进入');
              }else{
                  $('#result').html(dirName[direction]+'离开');
              }
    });

     很实用的一段代码

  • 相关阅读:
    asp.net pager
    asp.net 2.0
    mul page
    基于 Ajax 的持久对象映射(reship)
    asp.net run
    reship HttpProc
    some questions
    rss feed
    javascript function
    ioc
  • 原文地址:https://www.cnblogs.com/guojikun/p/6265436.html
Copyright © 2011-2022 走看看