当前位置:网站首页>获取鼠标移动的方向
获取鼠标移动的方向
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));
});边栏推荐
- Core and semiconductor "RF eda/ filter design platform" shines ims2022
- Three cache methods and principles
- 新捷途X70S上市8.79万起,空间安全越级,不愧是网红国民大7座SUV
- Mysql database DQL exercise
- 2020-12-20
- Case 2 of SQL performance degradation caused by modifying implicit parameters
- Greedy distribution problem (2)
- 2021-04-05
- 2021-03-06
- R language data preprocessing, converting type variables into factor variables, converting data sets into H2O format, and dividing data sets (training set, test set, verification set)
猜你喜欢

Rapideye, spot satellite remote sensing image data

2021-08-21

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

Generate detailed API and parameters of QR code using qrcodejs2

5 minutes to quickly launch web applications and APIs (vercel)

Reinforcement learning weekly (issue 50): saferl kit, gmi-drl, rp-sdrl & offline meta reinforcement learning

General trend wisdom to create inclined model and cut monomer

c语言---17 函数简介

Las point cloud create mesh

Spark RDD Programming Guide(2.4.3)
随机推荐
Mysql database DQL exercise
What are the indicators, dimensions and models in Business Intelligence BI data warehouse?
MySQL multi table operation exercise
General trend wisdom to create inclined model and cut monomer
Generate detailed API and parameters of QR code using qrcodejs2
Plan and change of continuous repair
2021-08-21
Help customers' digital transformation and build a new operation and maintenance system
新捷途X70S上市8.79万起,空间安全越级,不愧是网红国民大7座SUV
In a frame because it set 'X-FRAME-OPTIONS' to' deny '
C language -- 17 function introduction
How to manage tasks in note taking software such as flowus and notation?
Redis big key problem
《强化学习周刊》第50期:SafeRL-Kit、GMI-DRL、RP-SDRL & 离线元强化学习
组合总数[标准回溯 + 回溯技巧--降低栈深度]
ArcGIS application (20) the ArcGIS grid image symbol system prompts "this dataset does not have valid histogram required for classificati..."
A spark app demo
Valid parentheses
Some shaders in AB package do not trigger the callback of ipreprocessshaders
2021-08-22