Vue implements the magnifying glass function of the product details page

Vue implements the magnifying glass function of the product details page

This article shares the specific code of Vue to implement the magnifying glass of the product details page for your reference. The specific content is as follows

Contents in templates

<div class="productLeft">
   <!-- Middle left image -->
     <div class="mdImg">
         <img :src="require('../assets/imgs/details/'+mdImgUrl)" alt="">
     </div>
     <!-- Mask layer-->
     <div v-show="isShow" class="marks" :style="{top:top+'px',left:left+'px'}"></div>
     <!-- Mask layer glass superMarks-->
     <div @mouseenter="enter" @mouseleave="leave" @mousemove="marks" class="superMarks" ></div>
     <!--Small picture on the left-->
     <div class="smImg" >
         <!--Left button-->
         <div @click="prev" class="button-prev">
             <img src="../assets/icon/prev.png" >
         </div>
         <div class="smImgUl">
             <ul :style="{'margin-left':marginLeft+'px'}">
                 <li @mouseenter="enterLi(index)" v-for="(item,index) of list" :key="index">
                     < img :src="require('../assets/imgs/details/'+item.sm)" alt="">
                 </li>
             </ul>
         </div>
         <!-- Right Button -->
         <div @click="next" class="button-next">
             <img src="../assets/icon/next.png" >
         </div>
     </div>
    <!-- Large image on the left -->
     <div v-show="isShow" class="lgImg">
         <img :src="require('../assets/imgs/details/'+lgImgUrl)" alt="" :style="{top:topLgImg+'px',left:leftLgImg+'px'}">
     </div>
</div>

js:

< script >
import headerT from "./common/headerT.vue"
import header from "./common/Header.vue"
export default {
    data() {
        return {
            list:[{"sm":"s1.png","md":"s1.png","lg":"s1.png"},
            {"sm":"s2.png","md":"s2.png","lg":"s2.png"},
            {"sm":"s3.png","md":"s3.png","lg":"s3.png"},
            {"sm":"s4.png","md":"s4.png","lg":"s4.png"},
            {"sm":"s5.png","md":"s5.png","lg":"s5.png"},
            {"sm":"s6.png","md":"s6.png","lg":"s6.png"},
            {"sm":"s7.png","md":"s7.png","lg":"s7.png"},
            {"sm":"s8.png","md":"s8.png","lg":"s8.png"}],
            mdImgUrl:"s1.png",
            lgImgUrl:"s1.png",
            ulIndex:0, //Move a few li to the left
            marginLeft:0, //The distance to move left and right isShow:false, //Controls whether the mask layer marks and large images are displayed"
            left:0, //marks left position top:0, //marks down position leftLgImg:0, //large image lgImg move position topLgImg:0 //large image lgImg move position }
    },
    methods: {
        //When the mouse enters the small picture, the corresponding middle picture is displayed enterLi(e){
            //e is the corresponding subscript//console.log(e);
            this.mdImgUrl=this.list[e].md;
            this.lgImgUrl=this.list[e].lg;
        },

        //Click the left and right buttons to move the li in ul. Each li is 74px wide and ul is 370px wide to display 5 li.
        prev(){
            //Move left -
            if(this.ulIndex>-(this.list.length-5)){
                this.ulIndex--;
                this.marginLeft=this.ulIndex*74;
                //console.log(this.ulIndex)
            }
        },
        next(){
            //Move right++
            if(this.ulIndex<0){
                 this.ulIndex++;
                this.marginLeft=this.ulIndex*74;
                //console.log(this.ulIndex)
            }
        },
        
        //Mouse enters and leaves enter(){
            this.isShow=true
        },
        leave(){
            this.isShow=false
        },
        //Mask layer magnifying glass marks(e){
            //console.log(e.offsetX,e.offsetY) //The position of the mouse when it moves in
            var marksWidth=200;//marks width var marksHeight=200;//marks height this.left=e.offsetX-marksWidth/2;   
            this.top=e.offsetY-marksHeight/2;
            //console.log(this.left,this.top) 
            if(this.left<0){
                this.left=0;
            }else if(this.left>250){
                this.left=250;
            }
            if(this.top<0){
                this.top=0;
            }else if(this.top>250){
                this.top=250;
            }
            //console.log(this.left,this.top) 
            
            //The width and height of the medium image div is 450, and the width and height of the large image div is 800
            this.leftLgImg=-this.left*800/450;
            this.topLgImg=-this.top*800/450;
        }
    },
    computed: {
    },
    components:{
        "headerone":headerT,
        "headertwo":header
    },
    watch:
    },
}
</script>

CSS:

<style scoped>

    .content{
        width:1200px;
        margin:0 auto;
    }
    .content>.product{
        display: flex;
        justify-content: space-between;
    }
    /* Left side size image style*/
    .productLeft{
        width:450px;
        position: relative;
    }
    /* Middle image on the left */
    .mdImg,.mdImg>img{
        width:450px;
        height:450px;
    }
    /*Mask layer superMarks */
    .superMarks{
        width:450px;
        height:450px;
        background-color:rgba(220, 220, 220, 0);
        position:absolute;
        top:0px;
        left:0px;
    }
    /* Mask layer*/
    .marks{
        width:200px;
        height:200px;
        position:absolute;
        background-color:rgba(220, 220, 220, 0.5);
        /*top:0px; //Inline sets dynamic top and left
        left:0px;*/
    }
    /* Small image on the left */
    .smImg{
        display:flex;
        align-items: center;
        justify-content: space-between;
        overflow:hidden;
    }
    .smImgUl{
        overflow:hidden;
        width:370px;
    }
    .smImg ul{
        display: flex;
        width:370px;
        margin:0;
        padding:0;
    }
    .smImg ul>li{
        padding:0 3px;
    }
    .smImg img{
        height:60px;
        margin:4px;
    }
    /*Hide the large image on the left*/
    .lgImg{
        width:400px;
        height:400px;
        overflow: hidden;
        position:absolute;
        top:0px;
        left:450px;
        border:2px solid #aaa;
        background-color:#fff;
    }
    .lgImg img{
        width:800px;
        height:800px;
        position:absolute;
        /*top:100px;
        left:100px;*/
    }

    /* product right side */
    .productRight{
        width:700px;
        
    }
    /* Left and right buttons */
    .button-prev,.button-next{
        width:35px;
        height:35px;
        line-height: 30px;
        border:1px solid #ddd;
        border-radius:50%;
        text-align:center;
    }
    .button-prev:hover,.button-next:hover{
        background-color:#eee;
    }
    .button-prev>img,.button-next>img{
        width:20px;
        height:20px;
    }
</style>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue realizes the product magnifying glass effect
  • Example code of Vue3 encapsulated magnifying glass component
  • Vue3 realizes the image magnifying glass effect
  • Vue implements the magnifying glass effect of tab switching
  • Vue implements a simple magnifying glass effect
  • Vue implements a search box with a magnifying glass
  • Vue3.0 handwriting magnifying glass effect
  • Vue implements magnifying glass effect
  • A handwritten vue magnifying glass effect
  • Vue3 encapsulates the magnifying glass effect component of Jingdong product details page

<<:  How to implement scheduled backup and incremental backup of uploaded files in Linux

>>:  How to implement scheduled automatic backup of MySQL under CentOS7

Recommend

In-depth explanation of MySQL stored procedures (in, out, inout)

1. Introduction It has been supported since versi...

How to solve the problem of MySQL query character set mismatch

Find the problem I recently encountered a problem...

How to solve the problem that mysql cannot be closed

Solution to mysql not closing: Right-click on the...

Web page HTML code: production of scrolling text

In this section, the author describes the special...

Detailed explanation of MySQL cursor concepts and usage

This article uses examples to explain the concept...

How to manually install MySQL 5.7 on CentOS 7.4

MySQL database is widely used, especially for JAV...

How to use CSS media query aspect-ratio less

CSS media query has a very convenient aspect rati...

When is it appropriate to use dl, dt, and dd?

dl:Definition list Definition List dt:Definition t...

Explanation of MySQL index types Normal, Unique and Full Text

MySQL's index types include normal index, uni...

Summary of the use of element's form elements

There are many form elements. Here is a brief sum...

W3C Tutorial (1): Understanding W3C

W3C, an organization founded in 1994, aims to unl...

Perfect solution to Google Chrome autofill problem

In Google Chrome, after successful login, Google ...

Semantics, writing, and best practices of link A

The semantics, writing style, and best practices ...

Detailed introduction to CSS font, text, and list properties

1. Font properties color, specifies the color of ...