div js 缩放方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leixu1027/article/details/80519730

话不多说,上代码,

要的就是那种直接可以运行的的,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;
        }
    }

阅读更多
换一批

没有更多推荐了,返回首页