欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3?自定義圖片放大器效果的示例代碼

 更新時間:2022年07月23日 11:21:45   作者:梁云亮  
這篇文章主要介紹了vue3?自定義圖片放大器效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

效果

請?zhí)砑訄D片描述

具體代碼實現(xiàn)

創(chuàng)建商品圖片展示的vue頁面:ProductPicShow.vue

<script lang="ts" setup>
import { ref, computed } from 'vue'
import { useMouseInElement } from '@vueuse/core'

defineProps<{
  images: string[]
}>()
// 當(dāng)前顯示的圖片索引
let active = ref(0)
// ref 獲取 DOM 元素的位置
const target = ref(null)
// isisOutside為 true 的時候代表鼠標未進入目標元素,為 false 時代表鼠標進入目標元素
const { elementX, elementY, isOutside } = useMouseInElement(target)
// 遮罩半透明圖在商品大圖中的坐標位置
const position = computed(() => {
  let x = elementX.value - 100
  let y = elementY.value - 100
  if (x <= 0) x = 0
  if (x >= 200) x = 200
  if (y <= 0) y = 0
  if (y >= 200) y = 200
  return { x, y }
})
</script>
<template>
  <div class="product-image">
    <!-- 放大鏡的大盒子 -->
    <div
        class="large"
        :style="[
        {
          backgroundImage: `url(${images[active]})`,
          backgroundPosition: `-${position.x * 3}px -${position.y * 3}px`
        }
      ]"
        v-show="!isOutside"
    ></div>
    <div ref="target" class="middle">
      <img :src="images[active]" alt="" />
      <!-- 鼠標移動時的遮罩層 -->
      <div
          class="layer"
          v-show="!isOutside"
          :style="{ left: `${position.x}px`, top: `${position.y}px` }"
      ></div>
    </div>
    <ul class="small">
      <li
          v-for="(item, index) in images"
          :key="item"
          :class="{ active: index === active }"
          @mouseenter="active = index"
      >
        <img :src="item" alt="" />
      </li>
    </ul>
  </div>
</template>

<style scoped lang="less">
.product-image {
  width: 480px;
  height: 400px;
  position: relative;
  display: flex;
  z-index: 500;
  .large {
    position: absolute;
    top: 0;
    left: 412px;
    width: 600px;
    height: 600px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    background-repeat: no-repeat;
    background-size: 200% 200%;
    background-color: #f8f8f8;
  }
  .middle {
    width: 400px;
    height: 400px;
    background: #f5f5f5;
    position: relative;
    cursor: move;
    .layer {
      width: 200px;
      height: 200px;
      background: rgba(0, 0, 0, 0.2);
      left: 0;
      top: 0;
      position: absolute;
    }
  }
  .small {
    width: 80px;
    li {
      width: 68px;
      height: 68px;
      margin-left: 12px;
      margin-bottom: 15px;
      cursor: pointer;
      &:hover,
      &.active {
        border: 2px solid #27BA9B;
      }
    }
  }
}
</style>

使用:Product.vue

<template>
  <div class="product-info">
    <div class="media">
      <ProductPicShow :images="slidePics"/>
    </div>
  </div>
</template>
<script setup lang="ts">
import ProductPicShow from "@/views/product/components/ProductPicShow.vue"
</script>
<style scoped lang="less">
.product-info {
  min-height: 600px;
  background: #fff;
  display: flex;

  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
}
</style>

到此這篇關(guān)于vue3 自定義圖片放大器的文章就介紹到這了,更多相關(guān)vue3 圖片放大器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue中inheritAttrs的使用實例詳解

    Vue中inheritAttrs的使用實例詳解

    這篇文章主要介紹了Vue中inheritAttrs的使用實例詳解,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • Vue3環(huán)境安裝以及項目搭建全過程

    Vue3環(huán)境安裝以及項目搭建全過程

    Vue工程化項目環(huán)境配置還是比較麻煩的,下面這篇文章主要給大家介紹了關(guān)于Vue3環(huán)境安裝以及項目搭建的相關(guān)資料,文中通過圖文以及代碼介紹的非常詳細,需要的朋友可以參考下
    2023-12-12
  • vue如何通過src引用assets中的圖片

    vue如何通過src引用assets中的圖片

    這篇文章主要介紹了vue如何通過src引用assets中的圖片,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 深入理解Vue響應(yīng)式原理及其實現(xiàn)方式

    深入理解Vue響應(yīng)式原理及其實現(xiàn)方式

    Vue的響應(yīng)式原理是Vue最核心的特性之一,也是Vue能夠為開發(fā)者提供高效便捷的開發(fā)體驗的重要原因之一,這篇文章主要介紹了響應(yīng)式的原理及其實現(xiàn)方式,需要詳細了解可以參考下文
    2023-05-05
  • Vue3使用setup如何定義組件的name屬性詳解

    Vue3使用setup如何定義組件的name屬性詳解

    vue3中新增了setup,它的出現(xiàn)是為了解決組件內(nèi)容龐大后,理解和維護組件變得困難的問題,下面這篇文章主要給大家介紹了關(guān)于Vue3使用setup如何定義組件的name屬性的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • 深入探究Vue中$nextTick的實現(xiàn)原理

    深入探究Vue中$nextTick的實現(xiàn)原理

    這篇文章主要為大家詳細介紹Vue中$nextTick的實現(xiàn)原理,文中的示例代碼講解詳細,對我們深入了解Vue有一定的幫助,需要的小伙伴可以參考一下
    2023-06-06
  • Vant?UI中van-collapse下拉折疊面板默認展開第一項的方法

    Vant?UI中van-collapse下拉折疊面板默認展開第一項的方法

    之前做項目的時候,使用了Collapse折疊面板,下面這篇文章主要給大家介紹了關(guān)于Vant?UI中van-collapse下拉折疊面板默認展開第一項的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • Vue實現(xiàn)搜索 和新聞列表功能簡單范例

    Vue實現(xiàn)搜索 和新聞列表功能簡單范例

    本文通過實例代碼給大家介紹了Vue實現(xiàn)搜索 和新聞列表功能簡單范例,非常不錯,具有參考借鑒價值,感興趣的朋友一起看看吧
    2018-03-03
  • Vue3使用Proxy實現(xiàn)數(shù)據(jù)監(jiān)聽的原因分析

    Vue3使用Proxy實現(xiàn)數(shù)據(jù)監(jiān)聽的原因分析

    在本篇文章里小編給大家整理的是一篇關(guān)于Vue3使用Proxy實現(xiàn)數(shù)據(jù)監(jiān)聽的原因分析內(nèi)容,有需要的朋友們可以跟著學(xué)習(xí)參考下。
    2021-11-11
  • vue?element?el-select下拉滾動加載的方法

    vue?element?el-select下拉滾動加載的方法

    很多朋友都遇到這樣一個問題在使用vue+element的el-select下拉框加載返回數(shù)據(jù)太多時,會造成卡頓,用戶體驗欠佳,這篇文章主要介紹了vue?element?el-select下拉滾動加載方法,需要的朋友可以參考下
    2022-11-11

最新評論