想看原理,請留言,我補上
animation+定位動畫製作輪播圖
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>輪播</title>
<style>
big {
width: 1920px;
height: 500px;
overflow: hidden;
position: relative;
}
.small {
width: 1920px;
height: 500px;
position: absolute;
left: 0;
top: 0;
animation: move 5s infinite;
}
.small:nth-child(2) {
animation-delay: -2.5s;
}
@keyframes move {
0% {
transform: translate(1920px);
z-index: 2;
}
10% {
transform: translateX(0);
z-index: 2;
}
50% {
transform: translateX(0);
z-index: 2;
}
60% {
transform: translateX(-1920px);
z-index: 1;
}
100% {
transform: translateX(-1920px);
z-index: 1;
}
}
</style>
</head>
<body>
<div class="big">
<div class="small"><img src="./img/3.jpeg" alt=""></div>
<div class="small"><img src="./img/4.jpeg" alt=""></div>
</div>
</body>
</html>
animation動畫製作輪播圖
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.layer {
width: 1920px;
height: 500px;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
}
.slideshow {
width: 5760px;
height: 500px;
position: absolute;
animation: move 10s ease-in-out infinite;
}
img {
float: left;
width: 1920px;
height: 500px;
}
@keyframes move {
25% {
left: 0;
}
50% {
left: -1920px;
}
75% {
left: -1920px;
}
100% {
left: -3840px;
}
}
</style>
</head>
<body>
<div class="layer">
<div class="slideshow">
<img src="./img/pic-1.jpeg" alt="">
<img src="./img/pic-2.jpeg" alt="">
<img src="./img/pic-1.jpeg" alt="">
</div>
</div>
</div>
</body>
</html>
label+inut標籤製作手動輪播圖
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.viewport {
position: relative;
width: 1920px;
height: 500px;
overflow: hidden;
}
.wrap {
position: absolute;
width: 3840px;
overflow: hidden;
}
.wrap img {
float: left;
height: auto;
display: inline-block;
}
input {
display: none;
}
#pic1:checked~.wrap {
transform: translateX(-1920px);
transition: .3s linear;
}
#pic2:checked~.wrap {
transform: translateX(0);
transition: .3s linear;
}
.left,
.right {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 40px;
height: 80px;
line-height: 80px;
color: orange;
font-size: 22px;
text-align: center;
background-color: rgba(0, 0, 0.3);
}
.left {
left: 0;
}
.right {
right: 0;
}
</style>
</head>
<body>
<div class="viewport">
<input type="radio" name="slider" id="pic1">
<input type="radio" name="slider" id="pic2">
<div class="wrap">
<img src="img/pic-1.jpeg" alt="">
<img src="img/pic-2.jpeg" alt="">
</div>
</div>
<label for="pic1" class="left">左</label>
<label for="pic2" class="right">右</label>
</body>
</html>
animation(step屬性)製作自動輪播圖
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.layer {
width: 1920px;
height: 500px;
overflow: hidden;
}
.slideshow {
width: 3840px;
height: 500px;
animation: move 4s steps(2) infinite;
}
img {
float: left;
width: 1920px;
height: 500px;
}
@keyframes move {
100% {
transform: translateX(-3840px);
}
}
</style>
</head>
<body>
<div class="layer">
<div class="slideshow">
<img src="./img/pic-1.jpeg" alt="">
<img src="./img/pic-2.jpeg" alt="">
</div>
</div>
</div>
</body>
</html>