hooyantsing's Blog

P208_15_红心点赞案例详解

字数统计: 218阅读时长: 1 min
2020/04/24

P208 15 红心点赞案例详解

实战案例

介绍:涉及到jQuery的应用。点赞动画和颜色切换。

效果:

10a69afa59f47239b58f72ed7c45230e.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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

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

        main {
            position: relative;
        }

        main div {
            font-size: 2em;
            color: white;
            position: absolute;
            transition-duration: 1s;
            cursor: pointer;
        }

        .heart div {
            transform: scale(3);
            color: orangered;
            opacity: 0;
        }

        .heart div:nth-child(2) {
            transform: scale(1);
            color: orangered;
            opacity: 1;
        }
    </style>
</head>
<body>
<main onclick="change()">
    <div>赞</div>
    <div>赞</div>
</main>
<script>
    function change() {
        $('main').toggleClass('heart');
    }
</script>
</body>
</html>
CATALOG