实现场景:通过滚动中键切换图片等

mounted() {
    window.addEventListener('wheel', this.handleMouseWheel, {
      passive: false,
    })
},
beforeDestroy() {
    window.removeEventListener('wheel', this.handleMouseWheel, {
      passive: false,
    })
},
handleMouseWheel(e) {
	if (!window.scrollY) {
		// 禁止页面滚动
		// e.preventDefault()
		
		if (e.wheelDelta) {
			// 判断浏览器IE,谷歌滑轮事件
			if (e.wheelDelta > 0) {
				this.currentActive--
			}
			if (e.wheelDelta < 0) {
				// 当滑轮向下滚动时
				this.currentActive++
			}
		} else if (e.detail) {
			// Firefox滑轮事件
			if (e.detail > 0) {
				// 当滑轮向下滚动时
			}
			if (e.detail < 0) {
				// 当滑轮向上滚动时
				this.currentActive--
			}
		}
	}
}

Logo

前往低代码交流专区

更多推荐