惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
O
OpenAI News
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
Arctic Wolf
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
T
Tor Project blog
博客园_首页
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
S
Secure Thoughts
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Visual Studio Blog
J
Java Code Geeks
Cisco Talos Blog
Cisco Talos Blog
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
宝玉的分享
宝玉的分享
量子位
Last Week in AI
Last Week in AI
月光博客
月光博客
罗磊的独立博客
S
SegmentFault 最新的问题

博客园 - 华安

Unity 中区别,public 和 [SerializeField] Unity中 onCollisionEnter2D与OnTriggerEnter2D 区别 asp.netCore中给动态请求路径加客户端缓存 netCore中获取客户端真实的IP引起的思考 Unity 相机:正交 (Orthographic) vs 透视 (Perspective) unity中的button中的onclick控制面板中四个参数的意思分别是什么 微信小程序开发中触发 onshow的几种特殊情况 SQL Server备份心得 MYSQL 备份数据库 微信与支付支付功能开发 微信小程序中页面配置下拉刷新 unity中 相机没有视锥效果线框了,如何打开 JSONPath表达式 C# 中的操作JSON类 JObject cookie中的 HttpOnly 、Secure、SameSite 解释 Spring-boot 中基于 IP 的限流和自动封禁 Filter 登录 用 HMAC-SHA256 实现 TwoFA(二重验证)的坑 利用Spring Boot的 filter 结合ConcurrentHashMap 实现“同一IP每分钟最多允许300个404请求,超出后禁用30分钟访问” pixi-filters中的BackdropBlurFilter使用注意事项 PixiJS中的 SplitBitmapText.chars中的每个 BitmapText的x值分析 legend隐藏不想显示的图例 spring-boot HttpServletResponse response.sendRedirect是会跳转到 http而不是https springboot获取post请求参数 Javascript如何判断是触摸屏还是PC端 spring-boot中配置Mongodbd的问题小结 Rest Template中添加 PATCH请求。 CSS实现修改CheckBox样式 SpringBoot+Thyemleaf报错:Error resolving template Template might not exist or might not be accessible div display flex 如何出现横向滚动条
JavaScript获取鼠标点一个元素,获取鼠标点击的元素内的位置
华安 · 2025-12-02 · via 博客园 - 华安
function getEventPosition(event) {
    //检测是否是触摸屏设备
   let _isTouch = (function () { return navigator.maxTouchPoints > 0; })();
    // 使用 getBoundingClientRect() 获取更精确的位置
    const rect = canvas.getBoundingClientRect();
    let _eventClientObj = event;
    if (_isTouch) {
        _eventClientObj = event.touches[0];
    }
    const x = _eventClientObj.clientX - rect.left;
    const y = _eventClientObj.clientY - rect.top;
    //console.log(x, y, _eventClientObj.clientX, rect.left, event);
               

getBoundingClientRect() 是一个用于获取元素位置和尺寸信息的重要方法2。

‌核心功能‌
它返回一个DOMRect对象,包含以下关键属性23:

  • x / left:元素左边界相对于视口左侧的距离
  • y / top:元素上边界相对于视口顶部的距离
  • width:元素的宽度
  • height:元素的高度
  • right:元素右边界相对于视口左侧的距离
  • bottom:元素下边界相对于视口顶部的距离
const box = document.getElementById('box');
const rect = box.getBoundingClientRect();

console.log(rect.width);   // 元素的宽度
console.log(rect.height); // 元素的高度
console.log(rect.top);    // 元素上边界相对于视口顶部的距离