# 弹性过度

一切的过度皆应该由动画来完成

鸿蒙开机动画demo

<style>
.demo-harmony {
  background: black;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
}
.demo-harmony .ul {
  position: relative;
  width: 100px;
  height: 50px;
  padding: 10px;
  list-style: none;
  overflow: hidden;
  margin: 0;
  box-sizing: content-box;
}
.demo-harmony .ul:first-of-type {
  padding-bottom: 0
}
.demo-harmony .ul:last-of-type {
  padding-top: 0;
  margin-top: -2px;
  animation: harmony-container-move .1s 1.2s forwards
}

.demo-harmony .harmony {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 70px;
  height: 70px;
  border: 15px solid white;
  border-radius: 50%;
  transform: translateY(50%);
  box-shadow: 0 0 6px white, inset 0 0 6px white;
  animation: harmony-move 1.2s forwards;
  box-sizing: content-box;
}
.demo-harmony .ul:last-of-type > .harmony {
  top: auto;
  bottom: 10px;
  transform: translateY(-50%);
  filter: url(#blur)
}

.demo-harmony svg {
  width: 0;
  height: 0
}

@keyframes harmony-move {
  to { transform: none }
}

@keyframes harmony-container-move {
  to { margin-top: 0 }
}
</style>
<template>
  <div class="demo-harmony">
    <div class="container">
      <ul class="ul">
        <li class="harmony"></li>
      </ul>
      <ul class="ul">
        <li class="harmony"></li>
      </ul>
    </div>

    <svg>
      <filter id="blur">
        <feGaussianBlur in="SourceGraphic" stdDeviation="0 6"/>
      </filter>
    </svg>
  </div>
</template>
<script>
export default {
  mounted () {
    const filter = document.querySelector('feGaussianBlur')
    
    const clearFilter = () => {
      const value = parseFloat(filter.getAttribute('stdDeviation').split(' ')[1]) - 0.06
      
      if (value > 0) {
        filter.setAttribute('stdDeviation', `0 ${value}`)
        requestAnimationFrame(clearFilter)
      } else {
        return
      }
    }

    setTimeout(clearFilter, 1000)
  }
}
</script>
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
显示代码 复制代码
  • animation方案
<style scoped>
  main {
    width: 100%; height: 229px;
    display: flex;
  }
  label {
    margin: auto;
  }
  input {
    display: block;
    width: 229px;
    padding: .8em;
    outline: none;
    border: 1px solid #e3e3e3;
    border-radius: 2px;
  }
  input:focus,
  input:hover {
    border-color: #b4a078;
  }
  input:not(:placeholder-shown) {
    border-color: #be4141;
    box-shadow: 0 0 0 2px rgba(255, 100, 97, 0.2);
  }
  input:not(:placeholder-shown) + .poptip {
    color: #be4141;
  }
  input:valid {
    border-color: #b4a078;
    box-shadow: 0 0 0 2px rgba(180, 160, 120, 0.2);
  }
  input:valid + .poptip {
    color: unset;
  }
  input:not(:focus) + .poptip {
    transform: scale(0);
    animation: elastic-dec .25s;
  }
  
  input:focus + .poptip {
    transform: scale(1);
    animation: elastic-grow .45s;
  }
  .poptip {
    display: inline-block;
    width: 236px;
    font-size: 13px;
    padding: .6em;
    background: #fafafa;
    position: relative;
    margin-left: -3px;
    margin-top: 3px;
    border-radius: 2px;
    filter: drop-shadow(0 0 1px rgba(0, 0, 0, .23456));
    transform-origin: 15px -6px;
  }
  .poptip::before {
    content: "";
    position: absolute;
    top: -6px; left: 10px;
    border: 9px solid transparent;
    border-bottom-color: #fafafa;
    border-top-width: 0;
  }
  @keyframes elastic-grow {
    from {
        transform: scale(0);
    }
    70% {
        transform: scale(1.1);
        animation-timing-function: cubic-bezier(.1, .25, .1, .25);
    }
  }
  @keyframes elastic-dec {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(0);
        animation-timing-function: cubic-bezier(.25, .1, .25, .1);
    }
  }
</style>
<template>
  <main class="main">
    <label>
      <input
        required
        type="text"
        id="username1"
        autocomplete="off"
        placeholder="请输入内容"
        pattern="^\w+$"/>
      <span class="poptip">仅支持字母、数字和下划线组合!!</span>
    </label>
  </main>
</template>
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  • 三次贝塞尔cubic-bezier + transition方案
<style scoped>
  main {
    width: 100%; height: 229px;
    display: flex;
  }
  label {
    margin: auto;
  }
  input {
    display: block;
    width: 229px;
    padding: .8em;
    outline: none;
    border: 1px solid #e3e3e3;
    border-radius: 2px;
  }
  input:focus,
  input:hover {
    border-color: #b4a078;
  }
  input:not(:placeholder-shown) {
    border-color: #be4141;
    box-shadow: 0 0 0 2px rgba(255, 100, 97, 0.2);
  }
  input:not(:placeholder-shown) + .poptip {
    color: #be4141;
  }
  input:valid {
    border-color: #b4a078;
    box-shadow: 0 0 0 2px rgba(180, 160, 120, 0.2);
  }
  input:valid + .poptip {
    color: unset;
  }
  input:not(:focus) + .poptip {
    transform: scale(0);
    transition: transform .25s cubic-bezier(.25, .1, .25, .1);
  }
  input:focus + .poptip {
    transform: scale(1);
    transition: transform .4s cubic-bezier(.29, .15, .5, 1.46);
  }
  .poptip {
    display: inline-block;
    width: 236px;
    font-size: 13px;
    padding: .6em;
    background: #fafafa;
    position: relative;
    margin-left: -3px;
    margin-top: 3px;
    border-radius: 2px;
    filter: drop-shadow(0 0 1px rgba(0, 0, 0, .23456));
    transform-origin: 15px -6px;
  }
  .poptip::before {
    content: "";
    position: absolute;
    top: -6px; left: 10px;
    border: 9px solid transparent;
    border-bottom-color: #fafafa;
    border-top-width: 0;
  }
</style>
<template>
  <main class="main">
    <label>
      <input
        required
        type="text"
        id="username2"
        autocomplete="off"
        placeholder="请输入内容"
        pattern="^\w+$"/>
      <span class="poptip">仅支持字母、数字和下划线组合!!</span>
    </label>
  </main>
</template>
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

三次贝塞尔曲线cubic-bezier主要是为animation生成速度曲线的函数,语法是cubic-bezier(<x1>, <y1>, <x2>, <y2>),更多请参考:图形化工具cubic-bezier (opens new window)

上次更新: 2023-10-28