当前位置:网站首页>获取鼠标移动的方向
获取鼠标移动的方向
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));
});边栏推荐
- 2021-08-21
- 2021-08-22
- How to manage tasks in note taking software such as flowus and notation?
- Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file
- 下一个排列[发挥主观能动性发现规律]
- What if the SQL execution plan of the production system suddenly becomes worse?
- MySQL multi table operation
- Mysql database design
- A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]
- Core and semiconductor "RF eda/ filter design platform" shines ims2022
猜你喜欢

Some shaders in AB package do not trigger the callback of ipreprocessshaders

2021-08-21

Is it bad for NFT that the market starts to cool down?

2020-12-04
![Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]](/img/88/3a07589bf8edab618139b1bf1680e8.png)
Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]

What are the methods of software stress testing and how to select a software stress testing organization?
Task cache compilation caused by gradle build cache
Summary of transport layer knowledge points

The xinjietu x70s has been listed for 87900 times and has leapfrogged the class in space safety. It is worthy of being a 7-seat SUV of the National University of China

Rapideye, spot satellite remote sensing image data
随机推荐
2021-04-16
Pycharm configuring remote connection server development environment
What if the SQL execution plan of the production system suddenly becomes worse?
Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
MySQL functions
2020-12-04
How to continuously improve performance| DX R & D mode
Case 2 of SQL performance degradation caused by modifying implicit parameters
A spark app demo
Summary of transport layer knowledge points
Palindromes (simple version)
Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]
Considerations for using redisson to operate distributed queues
Live broadcast forecast the sixth issue of the webinfo lecture hall of the China Information Association will be broadcast on June 24
2021-04-05
volume rendering
A case of 94 SQL optimization (the writing method used is often rejected)
Wechat applet batch submission for review
The mental process and understanding of visual project code design
NFT can only be viewed from afar, but not blatantly played