<!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>手风 琴</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
width: 2400px;
}
#box {
width: 1200px;
height: 400px;
border: 2px solid red;
margin: 100px auto;
overflow: hidden;
}
#box li {
width: 240px;
height: 400px;
float: left;
}
</style>
</head>
<body>
<div id="box">
<ul>
<li><img src="images/1.jpg" alt="" /></li>
<li><img src="images/2.jpg" alt="" /></li>
<li><img src="images/3.jpg" alt="" /></li>
<li><img src="images/4.jpg" alt="" /></li>
<li><img src="images/5.jpg" alt="" /></li>
</ul>
</div>
</body>
<script src="./js/animation.js"></script>
<script>
// 获取相关元素
const lis = document.querySelectorAll("#box li");
console.log(lis);
// 遍历每一个li,鼠标移入移出事件
lis.forEach(function (li) {
li.onmouseover = function () {
// 排他,先统一
lis.forEach(function (item) {
// 动画
animation(item, 50, "width");
});
// 后特殊
animation(li, 1000, "width");
};
});
document.querySelector("#box").onmouseout = function () {
// 所有li恢复240
lis.forEach(function (li) {
animation(li, 240, "width");
});
};
</script>
</html>
JavaScript - WebAPI - 动画 - 案例 - 手风琴图
最新推荐文章于 2022-12-09 20:46:55 发布
关键词由CSDN通过智能技术生成