首页 > 教程
一张图片或Div不同位置点击事件
- 2025-04-07
- 1062 ℃
<!--
* @Author: Han
* @Date: 2021-10-27 17:34:01
* @LastEditors: Han
* @LastEditTime: 2021-10-27 17:36:35
* @FilePath: \Projectc:\Users\Han\Desktop\Untitled-1.html
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>一张图片或Div不同位置点击事件</title>
<style>
div {
position: relative;
margin: 100px auto;
width: 332px;
height: 332px;
border: 1px solid black;
}
div::before,
div::after {
content: '';
position: absolute;
background: black;
}
div::before {
height: 1px;
width: 100%;
top: 166px;
}
div::after {
height: 100%;
width: 1px;
left: 166px;
}
</style>
</style>
</head>
<body>
<div>
</div>
<script>
const btn = document.querySelector('div');
btn.onclick = function (e) {
alert(`点击了${e.offsetX >= 166 ? '右' : '左'}${ e.offsetY >= 166 ? '下' : '上'}`)
};
</script>
</body>
</html>上一篇:鼠标拖拽移动DIV
相关内容
Vue底层判断标签的性能优...
网页HTML特殊字符编码对照表
什么是深网?有危险吗?...
移动硬盘打不开千万别格式化
微信的尊老爱幼模式,关...
快速申请微软 ChatGPT ...
CSS动态渐变彩色文字代码
中毒的分类和诊断
-
批量重命名文件,怎样快速去除括号?去掉空格!
2021-10-29 1687
-
这些搜索方法可以助你事半功倍
2025-03-10 1350
-
易支付对接微信商户完整流程
2024-02-06 4104
-
注册申请微信公众号(服务号)
2024-05-13 1388
-
PHP读本地文件指定某行内容
2025-04-07 1071
-
测试了一堆远程控制工具,发现最好用的原来是它
2025-04-27 1125
-
Ant Design Vue 4.0 a-modal弹窗组件封装
2025-04-07 941
-
进化式产品创新
2024-05-29 1048
-
Vue3项目Build后部署在Nginx上F5刷新页面空白或404
2025-04-07 1010
-
(PHP)Redis Hash(哈希)操作
2025-04-07 1210
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


进入有缘空间
点击分享文章