div js 缩放方法

话不多说,上代码,

要的就是那种直接可以运行的的,ok的

    var elmnt = document.getElementByid('myId');
    zoomElement(elmnt) 
    zoomElement(elmnt) {
        if (elmnt.addEventListener) {
            // IE9, Chrome, Safari, Opera
            elmnt.addEventListener('mousewheel', MouseWheelHandler, false);
            // Firefox
            elmnt.addEventListener('DOMMouseScroll', MouseWheelHandler, false);
        }

        let i = 1;
        function MouseWheelHandler(e) {
            // cross-browser wheel delta
            const event = window.event || e; // old IE support
            event.preventDefault();
            const delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
            if (delta === 1) {
                i += 0.2;
                elmnt.style.transform = 'scale(' + i + ')';
            } else if (delta === -1) {
                if (i < 0.3) {
                    i = 0.2;
                } else {
                    i -= 0.2;
                }
                elmnt.style.transform = 'scale(' + i + ')';
            }
            return false;
        }
    }

你可能感兴趣的:(web前端)