<!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>
body {
background-color: #333333;
}
div {
width: 200px;
height: 200px;
border-radius: 50%;
background-color: #252526;
border: #000 1px solid;
margin: 200px auto;
}
</style>
</head>
<body>
<div></div>
<script>
// 1.获得灯泡和背景
const div = document.querySelector('div')
const body = document.querySelector('body')
// 2.给灯泡增加鼠标移入效果
div.addEventListener('mouseenter',function(){
div.style.backgroundColor = '#dcdcaa'
body.style.backgroundColor = '#ffd661'
})
// 3.增加鼠标移出效果
div.addEventListener('mouseleave',function(){
div.style.backgroundColor = '#252526'
body.style.backgroundColor = '#333333'
})
</script>
</body>
</html>
12-20
05-23
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-02
8857
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-14
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交