Просмотр исходного кода

树生长动画改用js实现(匀速)

任一存 3 лет назад
Родитель
Сommit
1e2018566e
1 измененных файлов с 22 добавлено и 7 удалено
  1. 22 7
      src/views/TreeAnimation.vue

+ 22 - 7
src/views/TreeAnimation.vue

@@ -8,6 +8,7 @@
       class="img-wrapper"
       class="img-wrapper"
     >
     >
       <img
       <img
+        id="tree-image"
         src="@/assets/image/tall-tree.png"
         src="@/assets/image/tall-tree.png"
         alt=""
         alt=""
         @load="onTreeImgLoad"
         @load="onTreeImgLoad"
@@ -58,6 +59,21 @@ export default {
   methods: {
   methods: {
     onTreeImgLoad() {
     onTreeImgLoad() {
       this.showTree = true
       this.showTree = true
+
+      setTimeout(() => {
+        const treeImageNode = document.getElementById('tree-image')
+        let bottom = 0
+        let imageHeight = treeImageNode.clientHeight
+        setInterval(() => {
+          bottom -= 4
+          if ((-bottom) >= (imageHeight - window.innerHeight)) {
+            treeImageNode.style.bottom = -(imageHeight - window.innerHeight) + 'px'
+          } else {
+            treeImageNode.style.bottom = bottom + 'px'
+          }
+        }, 30)
+      }, 1000)
+
       setTimeout(() => {
       setTimeout(() => {
         this.showSlideTip = true
         this.showSlideTip = true
         let mc = new Hammer(this.$refs['hammer-target'])
         let mc = new Hammer(this.$refs['hammer-target'])
@@ -89,14 +105,13 @@ export default {
     > img {
     > img {
       position: absolute;
       position: absolute;
       width: 100%;
       width: 100%;
-      top: 100%;
-      transform: translateY(-100%);
       opacity: 0;
       opacity: 0;
-      animation-name: emerge, start-slide, linear-slide, end-slide;
-      animation-duration: 1s, 3s, 35s, 3s;
-      animation-timing-function: linear, ease-in, linear, ease-out;
-      animation-delay: 0s, 1s, 4s, 39s;
-      animation-fill-mode: forwards, forwards, forwards, forwards;
+      bottom: 0;
+      animation-name: emerge;
+      animation-duration: 1s;
+      animation-timing-function: linear;
+      animation-delay: 0s;
+      animation-fill-mode: forwards;
     }
     }
   }
   }
   > .loading {
   > .loading {