js 鼠标滚轮控制图片放大缩小

 <img :src="ImgUrl" alt="" width="100%" @mousewheel="zoomimg($event)" id="ScrollImg">

 

// 缩放图片
    zoomimg(event) {
      var delta = 0;
      if (!event) event = window.event;
      if (event.wheelDelta) {
        delta = event.wheelDelta / 120;
        if (window.opera) delta = -delta;
      } else if (event.detail) {
        delta = -event.detail / 3;
      }
      var img = document.getElementById('ScrollImg')
      if (delta > 0) {
        var width = img.width;
        img.width = width * 1.1;
      } else if (delta < 0) {
        var width = img.width;
        if (width > 400) {
          img.width = width * 0.9;
        }
      }
    },

具体放大缩小限制大家自己配置。

 

posted @ 2020-06-30 11:33  叶子0321~  阅读(1768)  评论(0编辑  收藏  举报