当前位置:网站首页>获取鼠标移动的方向
获取鼠标移动的方向
2022-06-22 20:50:00 【紫微前端】
/*
* 获取元素移动的方向
* @param $element 元素的jQuery对象
* @param event 事件对象
* @return direction 返回一个数字:0:上,1:右,2:下,3:左
**/
function getDirection($element, event) {
var w = $element.width(),
h = $element.height(),
x =
(event.pageX - $element.offset().left - w / 2) *
(w > h ? h / w : 1),
y = (event.pageY - $element.offset().top - h / 2) * (h > w ? w / h : 1),
direction =
Math.round((Math.atan2(y, x) * (180 / Math.PI) + 180) / 90 + 3) % 4;
return direction;
}
$('#content')
.on('mouseenter', function (event) {
console.log('enter: ' + getDirection($(this), event));
})
.on('mouseleave', function (event) {
console.log('leave: ' + getDirection($(this), event));
});边栏推荐
- 立體渲染
- 使用Redisson操作分布式队列的注意事项
- ArcGIS应用(二十)Arcgis 栅格图像符号系统提示“This dataset does not have valid histogram required for classificati…”
- Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]
- Codeup longest palindrome substring
- A spark app demo
- Next permutation [give play to subjective initiative to discover laws]
- Greedy distribution problem (2)
- Mysql database DQL exercise
- Las point cloud create mesh
猜你喜欢

Grafana report display of sentinel based high availability current limiting system

The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?

Why is yuancosmos so popular? Is the 10trillion yuan shouted by the market boasting or the truth?

Introduction to database access tools

2021-04-14

Spark RDD Programming Guide(2.4.3)

Uniapp applet mall develops thinkphp6 points mall, group purchase and seckill packaged app

2021-03-06

2021-08-22

2021-03-06
随机推荐
The link added in the bottom menu cannot jump to the secondary page
2020-12-04
2021-04-14
Solution to cache inconsistency
使用HBuilder X编辑器安装终端窗口插件未响应的解决方案
组合总数[标准回溯 + 回溯技巧--降低栈深度]
2021-08-21
2021-08-21
R language builds a binary classification model based on H2O package: using H2O GLM constructs regularized logistic regression model and uses H2O AUC value of AUC calculation model
Several methods of changing 91 Oracle common table into partitioned table
2020-12-20
一个spark app demo
SSH method 2 for adding node nodes in Jenkins
A case of misuse of append
The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?
Is it bad for NFT that the market starts to cool down?
欧洲的龙之城|国家地理全球最浪漫最安全的目的地
[redisson] source code analysis of multilock
2021-05-02
Mysql database DML operation exercise