判断屏幕是否过大 或国小 进行 缩放达到自适应

     function scalScreen() {
            let docEl = document.documentElement;
            let scale = $(window).width() / 1920;
            let _width, _height;
            window.clientWidth = docEl.clientWidth;
            window.clientHeight = docEl.clientHeight;
            console.log(window.clientWidth)
            if (scale < 1) {
                _width = -(1920 - (1920 * scale)) / 2 + 'px';
                _height = -(1080 - (1080 * scale)) / 2 + 'px';
            } else {
                _width = ((1920 * scale) - 1920) / 2 + 'px';
                _height = ((1080 * scale) - 1080) / 2 + 'px';
            }

            $('#special_detail_index').css({
            'transform':'translate('+_width+','+_height+') scale('+scale+')'
            })
        }

         $(window).resize(function () {scalScreen();console.log(111)})
        scalScreen()

 

posted @ 2021-11-15 14:53  还有什么值得拥有  阅读(46)  评论(0编辑  收藏  举报