对某个div进行缩放,实现局部滚动缩放
2021-09-02 本文已影响0人
板栗炖牛肉
前言
- 页面存在多个div,现在我鼠标滚动缩放(浏览器缩放)只缩放其中一个div
- 对设置调整浏览器百分比无效
解决方案
- 添加滚动监听
window.addEventListener('mousewheel', this.zoomMonitor, {passive: false});
/**
* 缩放监听
* @param event
*/
zoomMonitor = (event) => {
let that = this;
if (event.ctrlKey === true || event.metaKey) {
event.preventDefault();
}
if (turnOnZoom) {
let div = document.getElementById("layout-content");
that.state.zoom += -event.deltaY / 1000;
div.style.zoom = that.state.zoom;
}
};
- 完结,很简单