vue中html代码
<template>
<div id="app" >
<div class="demo" @mousewheel="mousewheel">
<img class="img-sty"
:style="{transform: transform()}"
src="@/assets/icon.svg">//图片引入路径
</div>
</div>
</template>
vue中js代码:
data(){
return {
Xscaling: 0.1,
Yscaling: 0.1,
transform() {
return `scale(${this.Xscaling}, ${this.Yscaling})`
}
}
},
methods:{
// 鼠标滑轮转动时改变缩放大小
mousewheel(e){
var num= e.deltaY / 1000 //e.deltaY为上下转动时的值为100,-100
this.Xscaling += num
this.Yscaling += num
}
}
vue中的css代码:
.demo{
width: 100%;
margin: 0 0 20px;
text-align: center;
}
.img-sty{
width: 500px;
height: 500px;
overflow: hidden;
background-repeat: no-repeat;
}