当前位置:网站首页>Get the direction of mouse movement
Get the direction of mouse movement
2022-06-23 00:45:00 【Ziwei front end】
/*
* Get the direction of element movement
* @param $element Elemental jQuery object
* @param event Event object
* @return direction Return a number :0: On ,1: Right ,2: Next ,3: Left
**/
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));
});边栏推荐
- MD5加密+盐值工具类
- 62. different paths
- New paradigm of semantic segmentation! Structtoken: Rethinking the per pixel classification paradigm
- How to get started with machine learning?
- Leetcode question brushing - 715 Range module
- #yyds干货盘点#尾递归比递归好在哪儿
- 黄金etf持仓量如何算
- How Huawei cloud implements a global low delay network architecture for real-time audio and video [Part 1]
- LINQ query
- 每日刷题记录 (一)
猜你喜欢

SAP UI5 应用开发教程之一百零二 - SAP UI5 应用的打印(Print)功能实现详解

Read Amazon memorydb database based on redis

EasyCVR使用RTMP推流时不显示界面如何解决?

TIDB监控升级解决panic的漫漫探索之路

Using geTx to build a more elegant structure of flutter pages

New progress in the construction of meituan's Flink based real-time data warehouse platform

【机器学习-西瓜书】更文挑战【Day1】:1.1 引言

Dig three feet to solve the data consistency problem between redis and MySQL

Typecho仿卢松松博客主题模板/科技资讯博客主题模板

How to set the power-off auto start of easycvr hardware box
随机推荐
二叉树转字符串及字符串转二叉树
cadence SPB17.4 - allegro - 優化指定單條電氣線折線連接角度 - 折線轉圓弧
數據庫中數據的儲存結構和方式是什麼?
Yyds dry goods counting tail recursion is better than recursion
[launch] redis Series 2: data persistence to improve availability
最安全的现货白银的心理分析
Shell 查看帮助
How do beginners get started quickly and learn deeply?
图神经网络有哪些用途和应用?
SAP ui5 application development tutorial 103 - how to consume the trial version of the third-party library in SAP ui5 applications
[UVM] don't say that your VIP can't use ral model
使用GetX构建更优雅的Flutter页面结构
每日刷题记录 (一)
ROS2暑期学校 ROS2 Summer School 2022-转-
SAP ui5 application development tutorial 103 - how to consume third-party libraries in SAP ui5 applications
Kunlun distributed database sequence function and its implementation mechanism
工程目录导航
ROS1Noetic在Win11中安装记录
Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
3dMax建模笔记(一):介绍3dMax和创建第一个模型Hello world