hooyantsing's Blog

P235_27_纯CSS的网站轮换图太容易了

字数统计: 230阅读时长: 1 min
2020/04/25

P235 27 纯CSS的网站轮换图太容易了

实战案例

效果:

86037a03d0ac3278c3f166563959a2a3.png

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100vw;
            height: 100vh;
        }

        main {
            width: 400px;
            height: 300px;
            overflow: hidden;
        }

        article {
            display: grid;
            grid-template: 1fr / repeat(4, 400px);
            animation-name: slide;
            animation-duration: 4s;
            animation-iteration-count: infinite;
            animation-timing-function: steps(4, end);
            transform: translateX(0);
        }

        article:hover {
            animation-play-state: paused;
        }

        div {
            overflow: hidden;
        }

        img {
            width: 100%;
        }

        @keyframes slide {
            to {
                transform: translateX(-1600px);
            }
        }
    </style>
</head>
<body>
<main>
    <article>
        <div><img src="1.jpg"></div>
        <div><img src="2.jpg"></div>
        <div><img src="3.jpg"></div>
        <div><img src="4.jpg"></div>
    </article>
</main>
</body>
</html>
CATALOG