hooyantsing's Blog

P198_5_transitionend动画API接口

字数统计: 289阅读时长: 1 min
2020/04/23

P198 5 transitionend动画API接口

transitionend

JS代码中的参数,用于监听CSS动画完成后触发动作。

实战案例

介绍:涉及到js的应用。后盾人图块旋转一周后,下面的文字从右侧移动过来并固定在图块底部。

效果:

724cf3767c1a3243ab0de712bad0447f.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
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

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

        main {
            width: 200px;
            height: 200px;
        }

        div {
            width: 200px;
            height: 200px;
            position: relative;
        }

        div::before {
            content: '后盾人';
            position: absolute;
            width: 200px;
            height: 200px;
            border-radius: 10%;
            font-size: 3em;
            background: #95a5a6;
            display: flex;
            justify-content: center;
            align-items: center;
            transition-duration: 2s;
            cursor: pointer;
        }

        div:hover::before {
            transform: rotate(360deg);
        }

        div::after {
            content: 'houdunren.com';
            position: absolute;
            bottom: -55px;
            width: 200px;
            color: #95a5a6;
            text-align: center;
            font-size: 1.8em;
            transform: translateX(-1200px) skew(45deg);
            transition-duration: 1.5s;
        }

        div.move::after {
            transform: translateX(0px);
        }
    </style>
</head>
<body>
<main>
    <div></div>
</main>
<script>
    document.querySelector('div').addEventListener('transitionend', function (e) {
        document.querySelector('div').className = 'move'
    })
</script>
</body>
</html>
CATALOG