Code Monkey home page Code Monkey logo

vue-img-magnifier's Introduction

vue-img-magnifier 图片放大镜

支持Vue2.0+, 支持Nuxt.js

安装

npm install --save vue-img-magnifier

or

yarn add vue-img-magnifier

配置js

import Magnifier from 'vue-img-magnifier'
Vue.use(Magnifier, [options])

配置css

@import '~vue-img-magnifier/style.css'

or

import 'vue-img-magnifier/style.css'

使用非常简单,在img容器写上指令 v-magnifier, 然后给img绑定data-large-img-url大图地址即可

<template>
    <div>
        <div class="magnifier-thumb-wrapper" v-magnifier="options">
            <img :src="img" class="img" :data-large-img-url="img"/>
        </div>
        <div @click="changeImg">change img</div>
    </div>
</template>
<script>
export default {
    data(){
        return {
          imgs: [
             "http://upload.wikimedia.org/wikipedia/commons/thumb/9/94/Starry_Night_Over_the_Rhone.jpg/1200px-Starry_Night_Over_the_Rhone.jpg",
             "https://lowvelder.co.za/wp-content/uploads/sites/44/2017/12/desert-2340326_960_7_15745.jpg"
          ],
          active: 0,
          options: {
              // magnifier options
          }
        }
    },
    computed:{
      img(){
       return this.imgs[this.active] 
      } 
    },
    methods: {
      changeImg(){
        this.active = this.active? 0:1
      }
    }
}
</script>

options相关配置项

属性名 默认值 说明
width 0 预览框的宽度,�不设置高度,自动按照小图的比例计算高度
height 0 预览框的高度,�不设置宽度,自动按照小图的比例计算宽度
zoom 3 缩放比例

vue-img-magnifier's People

Contributors

wwo-demo avatar

Stargazers

 avatar Calvin Hong avatar Chenn avatar

Watchers

James Cloos avatar Calvin Hong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.