<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body,
html {
width: 100%;
height: 100%;
margin: 0;
font-family: "微軟雅黑";
}
#center {
display: flex;
justify-content: center;
align-items: center;
}
.iamge2,
.iamge3,
.iamge4 {
opacity: 0;
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
@keyframes cf4FadeInOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#cf4a {
position: relative;
height: 280px;
width: 450px;
margin: 0 auto;
overflow-x: hidden;
border: 1px solid #ccc;
background: #ccc
}
.iamge1 {
animation-name: cf4FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 1s;
animation-direction: alternate;
}
.iamge2 {
animation-name: cf4FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 2.5s;
animation-direction: alternate;
}
.iamge3 {
animation-name: cf4FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 4.5s;
animation-direction: alternate;
}
.iamge4 {
animation-name: cf4FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 6s;
animation-direction: alternate;
}
</style>
<script type="text/javascript" src="./jquery-3.3.1.min.js"></script>
<title>animate demo</title>
</head>
<body id="center">
<div id="cf4a">
<img class="iamge1" src="./images/1.jpg" />
<img class="iamge2" src="./images/2.jpg" />
<img class="iamge3" src="./images/3.jpg" />
<img class="iamge4" src="./images/4.jpg" />
</div>
</body>
</html>
- 這只是靜態樣式,其中有很多重複的,可以結合sass將公共的樣式提取出來
- 對於動態的樣式,可以結合sass的循環語句進行循環生成css
- 推薦在循環遍歷照片的時候添加對應的css以便達到自適應圖片數量的切換效果