菜鸟笔记
提升您的技术认知

div js 缩放方法-ag真人游戏

话不多说,上代码,

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