Vue.js implements the nine-grid image display module

Vue.js implements the nine-grid image display module

I used Vue.js to make a nine-grid image display module, which can be clicked to zoom.

The actual effect of the module

Nine-grid thumbnail effect

After zooming in

Code

HTML

<template>
<div class="SongList">
//Use v-for loop to render thumbnails <div class="covers" :style="{display:MinDisplay}">
         <div class="cover" v-for="(img,index) in imgs" :key='img'><img :src="img.src" width="90%" class="min" @click="ZoomIn(index)" alt=""></div>
       </div>
 // Render the enlarged image <div class="max" :style="{display:display}">
            <div @click="ZoomOut" v-for="(img,index) in imgs" :key='img' :class="[index===ShowIndex?'active':'None']" ><img :src="img.src" width="100%"></div>
            //Navigation map below the enlarged image <div class="small">
                <div :class="[{'smallActive':index===ShowIndex},'cover-small']" v-for="(img,index) in imgs" :key='img' @click="select(index)" ><img :src="img.src" width="90%"></div>
            </div>
        </div>
    </div>
</template>

CSS

<style scoped>
    .SongList{
        width: 40%;
    }
    .covers{
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    .cover{
        display: flex;
        justify-content: center;
        width: 33%;
        margin: 10px 0;
    }
    .min{
        border-radius: 10px;
        cursor: zoom-in;
    }
    .max{
        cursor: zoom-out;
        width: 100%;

    }
    .small{
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    .cover-small{
        display: flex;
        justify-content: center;
        width: 10%;
        margin: 10px 0;
        opacity: 0.6;
        cursor: pointer;
    }
    .cover-small:hover{
        opacity: 1;
    }
    .active{
        display: flex;
    }
    .None{
        display: none;
    }
    .smallActive{
        opacity: 1;
    }

</style>

Javascript

<script>
    export default {
        name: "SongList",
        data:function() {
            return {
                ShowIndex:0,
                display: 'none',
                MinDisplay:'flex',
                //When using v-for loop to render images in Vue template, you cannot directly use the local location of the image file imgs:[
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                    {"src":require('***.jpg')},
                ]

            };
        },
        methods:{
            ZoomIn(i){
               this.display='block';
                this.MinDisplay='none';
                this.ShowIndex=i;
            },
            ZoomOut(){
                this.display='none';
                this.MinDisplay='flex';
            },
            select(i){
                this.ShowIndex=i;


            }
        }
    }

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 component to realize mobile terminal nine-square grid turntable lottery
  • Jiugongge lottery function based on VUE
  • A complete example of a nine-square puzzle game implemented by jQuery+vue.js [with source code download]

<<:  HTML table markup tutorial (41): width and height attributes of the table header WIDTH, HEIGHT

>>:  How to enable Swoole Loader extension on Linux system virtual host

Recommend

How to move a red rectangle with the mouse in Linux character terminal

Everything is a file! UNIX has already said it. E...

How to change the root password in MySQL 5.7

Starting from MySQL 5.7, many security updates ha...

Detailed explanation of vite2.0+vue3 mobile project

1. Technical points involved vite version vue3 ts...

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

The unreasonable MaxIdleConns of MySQL will cause short connections

1 Background Recently, some performance issues ha...

How to install PostgreSQL and PostGIS using yum on CentOS7

1. Update the yum source The PostgreSQL version o...

Tutorial on how to install htop on CentOS 8

If you are looking to monitor your system interac...

How to write a MySQL backup script

Preface: The importance of database backup is sel...

A brief discussion on the $notify points of element

My original intention was to encapsulate the $not...

Graphical explanation of the underlying principle of JavaScript scope chain

Table of contents Preface Scope 1. What is scope?...

Use CSS variables to achieve cool and amazing floating effects

Recently, I found a fun hover animation from the ...

React tsx generates random verification code

React tsx generates a random verification code fo...