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

Summary of MySQL character sets

Table of contents Character Set Comparison Rules ...

How to install JDK 13 in Linux environment using compressed package

What is JDK? Well, if you don't know this que...

Solve the scroll-view line break problem of WeChat applet

Today, when I was writing a small program, I used...

Some "pitfalls" of MySQL database upgrade

For commercial databases, database upgrade is a h...

Detailed explanation of MySQL partition table

Preface: Partitioning is a table design pattern. ...

The button has a gray border that is ugly. How to remove it?

I used the dialog in closure and drew a dialog wit...

Teach you how to deploy zabbix service on saltstack

Table of contents Saltstack deploys zabbix servic...

Introduction to HTML page source code layout_Powernode Java Academy

Introduction to HTML page source code layout This...

Detailed tutorial on compiling and installing MySQL 8.0.20 from source code

In the previous article, we introduced: MySQL8.0....

How to solve the problem of MySQL query character set mismatch

Find the problem I recently encountered a problem...

Some CSS questions you may be asked during an interview

This article is just to commemorate those CSS que...

Friendly Alternatives to Find Tool in Linux

The find command is used to search for files in a...

Detailed explanation of Object.create instance usage in js

1. Create a new object using the Object.create() ...

JavaScript to achieve all or reverse selection function

This article shares the specific code of JavaScri...