chenlei преди 1 година
родител
ревизия
804bfac558
променени са 4 файла, в които са добавени 65 реда и са изтрити 63 реда
  1. 1 0
      package.json
  2. 2 0
      src/main.js
  3. 50 63
      src/views/BambooHotView3/index.vue
  4. 12 0
      yarn.lock

+ 1 - 0
package.json

@@ -25,6 +25,7 @@
     "vue": "^3.2.13",
     "vue-router": "^4.0.3",
     "vue-touch": "^2.0.0-beta.4",
+    "vue3-lazyload": "^0.3.8",
     "vue3-touch-events": "^4.1.8",
     "vuex": "^4.0.0"
   },

+ 2 - 0
src/main.js

@@ -13,6 +13,7 @@ import 'element-plus/dist/index.css'
 import { Swiper, SwiperSlide } from 'swiper/vue'
 import 'swiper/css'
 import 'swiper/css/pagination' // 分页器样式
+import VueLazyLoad from 'vue3-lazyload'
 // import 'default-passive-events'
 
 import BtnBack from '@/components/BtnBack.vue'
@@ -94,6 +95,7 @@ app.use(store)
   .use(VueViewer)
   .use(ElementPlus)
   .use(Vue3TouchEvents)
+  .use(VueLazyLoad)
   .component('BtnBack', BtnBack)
   .component('BtnClickMe', BtnClickMe)
   .component('OperationTip', OperationTip)

+ 50 - 63
src/views/BambooHotView3/index.vue

@@ -33,7 +33,11 @@
           hide: hotVisible && checkedHotId !== 1
         }"
       >
-        <img src="./images/bamboo1.png">
+        <img
+          v-lazy="{
+            src: Bamboo1Img,
+          }"
+        >
 
         <div
           class="bamboo-hot2__hot"
@@ -53,15 +57,14 @@
         }"
       >
         <img
-          src="./images/bamboo2.png"
-          @load="handleBambooOffset(2)"
+          v-lazy="{
+            src: Bamboo2Img,
+          }"
         >
       </div>
       <div
+        v-if="!hotVisible"
         class="bamboo-hot2__hot b2"
-        :class="{
-          hide: hotVisible
-        }"
         @click="handleHot(2)"
       >
         <p>紫竹</p>
@@ -74,15 +77,14 @@
         }"
       >
         <img
-          src="./images/bamboo3.png"
-          @load="handleBambooOffset(3)"
+          v-lazy="{
+            src: Bamboo3Img,
+          }"
         >
       </div>
       <div
+        v-if="!hotVisible"
         class="bamboo-hot2__hot b3"
-        :class="{
-          hide: hotVisible
-        }"
         @click="handleHot(3)"
       >
         <p>梅鹿竹</p>
@@ -95,8 +97,9 @@
         }"
       >
         <img
-          src="./images/bamboo4.png"
-          @load="handleBambooOffset(4)"
+          v-lazy="{
+            src: Bamboo4Img,
+          }"
         >
 
         <div
@@ -117,15 +120,14 @@
         }"
       >
         <img
-          src="./images/bamboo7.png"
-          @load="handleBambooOffset(7)"
+          v-lazy="{
+            src: Bamboo7Img,
+          }"
         >
       </div>
       <div
+        v-if="!hotVisible"
         class="bamboo-hot2__hot b7"
-        :class="{
-          hide: hotVisible
-        }"
         @click="handleHot(7)"
       >
         <p>湘妃竹</p>
@@ -138,8 +140,9 @@
         }"
       >
         <img
-          src="./images/bamboo8.png"
-          @load="handleBambooOffset(8)"
+          v-lazy="{
+            src: Bamboo8Img,
+          }"
         >
 
         <div
@@ -155,7 +158,7 @@
 
       <div
         ref="bambooWrapBg"
-        class="bamboo-hot2-bg-wrap"
+        class="bamboo-hot2-g-wrap"
       >
         <img
           v-if="bgImgLoaded"
@@ -198,14 +201,26 @@
 import { ref, watch, onBeforeUnmount } from 'vue'
 import { useRouter } from 'vue-router'
 import useSizeAdapt from "@/useFunctions/useSizeAdapt"
+import Bamboo1Img from "./images/bamboo1.png"
+import Bamboo2Img from "./images/bamboo2.png"
+import Bamboo3Img from "./images/bamboo3.png"
+import Bamboo4Img from "./images/bamboo4.png"
+import Bamboo7Img from "./images/bamboo7.png"
+import Bamboo8Img from "./images/bamboo8.png"
 
+const {
+  windowSizeInCssForRef,
+  windowSizeWhenDesignForRef,
+} = useSizeAdapt()
+const match = windowSizeInCssForRef.value.match(/\d+/)
+const maxTranslateXLength = 1000 / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10)
 let itemScrollMap = {
   1: 0,
-  2: 0,
-  3: 0,
-  4: 450,
-  7: 0,
-  8: 1048,
+  2: 230 / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10),
+  3: 280 / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10),
+  4: 640 / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10),
+  7: 900 / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10),
+  8: 840 / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10),
 }
 const ITEM_INFO_MAP = {
   1: {
@@ -236,10 +251,6 @@ const ITEM_INFO_MAP = {
 
 const titShow = ref(true)
 const bgImgLoaded = ref(false)
-const {
-  windowSizeInCssForRef,
-  windowSizeWhenDesignForRef,
-} = useSizeAdapt()
 const router = useRouter()
 
 const bambooWrap = ref()
@@ -261,41 +272,11 @@ const handleHot = (id) => {
   translateX.value = itemScrollMap[id]
 }
 
-const handleBambooOffset = (target) => {
-  let temp = 0
-
-  if ([7, 8].includes(target)) {
-    if (target === 7) {
-      temp = window.innerWidth * 0.2
-    } else {
-      temp = window.innerWidth * 0.2
-    }
-
-    itemScrollMap[target] = maxTranslateXLength - temp
-    return
-  }
-
-  const offset = window.innerWidth / 6
-  const left = document.getElementsByClassName(`bamboo-hot2-b${target}`)?.[0].getBoundingClientRect().left
-
-  switch (target) {
-  case 3:
-    temp = window.innerWidth / 3
-    break
-  case 4:
-    temp = -(window.innerWidth * 0.25)
-    break
-  }
-  itemScrollMap[target] = left - offset + temp
-}
-
 // 动画帧相关
 const lastAnimationTimeStamp = ref(0)
 const animationFrameId = ref(0)
 const moveSpeed = ref(0)
 const translateX = ref(0)
-const match = windowSizeInCssForRef.value.match(/\d+/)
-const maxTranslateXLength = (window.innerWidth * 3 - 150) / Number(windowSizeWhenDesignForRef.value) * parseInt(match[0], 10)
 const lastMoveEventTimeStamp = ref(0)
 const isMouseDown = ref(false)
 const isMove = ref(false)
@@ -408,10 +389,12 @@ onBeforeUnmount(() => {
 img {
   pointer-events: none;
 }
+:deep([class^="bamboo-hot2-b"] img[lazy=loaded]) {
+  opacity: 1;
+}
 
 .hide {
   opacity: 0 !important;
-  animation: none !important;
 }
 
 [class^="bamboo-hot2-b"] {
@@ -421,7 +404,9 @@ img {
   z-index: 3;
 
   img {
+    opacity: 0;
     height: 100%;
+    transition: opacity linear .2s;
   }
 }
 
@@ -496,8 +481,10 @@ img {
     font-size: 12px;
     font-family: KaiTi;
     writing-mode: vertical-rl;
-    animation: breathing linear 2s infinite;
 
+    &:not(.hide) {
+      animation: breathing linear 2s infinite;
+    }
     &::before {
       content: '';
       display: block;
@@ -584,7 +571,7 @@ img {
     transition: opacity linear .2s;
     z-index: 3;
   }
-  &-bg-wrap {
+  &-g-wrap {
     width: fit-content;
     height: 100%;
     position: relative;

+ 12 - 0
yarn.lock

@@ -6370,6 +6370,11 @@ vue-demi@*, vue-demi@>=0.14.8:
   resolved "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.14.8.tgz"
   integrity sha512-Uuqnk9YE9SsWeReYqK2alDI5YzciATE0r2SkA6iMAtuXvNTMNACJLJEXNXaEy94ECuBe4Sk6RzRU80kjdbIo1Q==
 
+vue-demi@^0.12.5:
+  version "0.12.5"
+  resolved "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.12.5.tgz#8eeed566a7d86eb090209a11723f887d28aeb2d1"
+  integrity sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==
+
 vue-eslint-parser@^8.0.1:
   version "8.3.0"
   resolved "https://registry.npmmirror.com/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz"
@@ -6427,6 +6432,13 @@ vue-touch@^2.0.0-beta.4:
     rollup-plugin-commonjs "^7.0.0"
     rollup-plugin-node-resolve "^2.0.0"
 
+vue3-lazyload@^0.3.8:
+  version "0.3.8"
+  resolved "https://registry.npmmirror.com/vue3-lazyload/-/vue3-lazyload-0.3.8.tgz#82749a6b89a4d475c9a7fa409d0cff6c4abbd59d"
+  integrity sha512-UiJHRT7mzry102WbhtrRgJh+f8Z8u4Z+H1RU4dvPmQeq7wFSDFxZB9iJOWGihH2FscXN/8rMGLDOQJAmjwqpCg==
+  dependencies:
+    vue-demi "^0.12.5"
+
 vue3-touch-events@^4.1.8:
   version "4.1.8"
   resolved "https://registry.npmjs.org/vue3-touch-events/-/vue3-touch-events-4.1.8.tgz#0cc7389a9fc2ecc6b34095b27d7174d5d3edc300"