<style>
  html,body{margin:0;padding:0;}
  #wrap{width:300px;height:300px;background:#33aa00;margin:50px;display:inline-block;font-size:50px;text-align:center;line-height:300px;}
</style>
  <div ,
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.floor(((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90);
  var eventType = e.type;
  var dirName = new Array('上方','右侧','下方','左侧');
  if(e.type == 'mouseenter'){
    $(this).html(dirName[direction]+'进入');
  }else{
    $(this).html(dirName[direction]+'离开');
  }
});
</script>

相关文章:

  • 2021-06-03
  • 2022-12-23
  • 2021-07-07
  • 2021-06-11
  • 2022-12-23
  • 2022-03-02
  • 2021-11-29
猜你喜欢
  • 2021-12-10
  • 2022-12-23
  • 2022-02-14
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案