<!DOCTYPE html>
<html lang="en">
<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>Document</title>
<style>
#box {
width: 600px;
background-color: red;
}
</style>
</head>
<body>
<div id="box"><img src="./images/cat.jpg" alt="" id="img"></div>
<script>
// onclick 单击事件
// ondbclick 双击事件
window.ondblclick = function () {
console.log("双击...");
}
//oncontextmenu 右键
document.oncontextmenu = function () {
console.log("右键....");
}
// onmousemove 鼠标移动
var box = document.getElementById("box");
box.onmousemove = function () {
console.log("鼠标在移动");
}
// onmouseover 鼠标悬停事件
box.onmouseover = function () {
img.src = "./images/cat2.jpg"
}
// onmouseout 鼠标离开事件
box.onmouseout = function () {
img.src = "./images/cat.jpg"
}
// onmousedown 鼠标按下
box.onmousedown = function () {
this.style.backgroundColor = "orange"
}
// onmouseup 鼠标松开事件
box.onmouseup = function () {
this.removeAttribute("style")
}
</script>
</body>
</html>
js 鼠标事件
最新推荐文章于 2022-07-19 16:14:00 发布