cuiqian2004
2025-05-16 9104222d52107d6244d034e4bbfa1c6408376900
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//- 设置html标签font-size
    (function(doc, win) {
        var _root = doc.documentElement,
            resizeEvent = 'orientationchange' in window ? 'orientationchange' : 'resize',
            resizeCallback = function() {
                var clientWidth = _root.clientWidth,
                    fontSize = 100;
                if (!clientWidth) return;
                if (clientWidth < 750) {
                    fontSize = 100 * (clientWidth / 375);
                } else {
                    fontSize = 100 * (750 / 375);
                }
                _root.style.fontSize = fontSize + 'px';
            };
        if (!doc.addEventListener) return;
        win.addEventListener(resizeEvent, resizeCallback, false);
        doc.addEventListener('DOMContentLoaded', resizeCallback, false);
    })(document, window);
    //字体大小的自适应,加上class=autosize即可
    $(function() {
        function e() {
            var e = document.documentElement.clientWidth;
            var font_size = e * .04 + "px";
            var font_size_small = e * .03 + "px";
            var font_size_big = e * .05 + "px";
            //var padding = e * .01 ;
            //if(padding>10){padding = 10}
            $('.autosize').css('font-size', font_size);
            $('.autosize2').css('font-size', font_size_small);
            $('.autosize3').css('font-size', font_size_big);
            //$('.swiper-slide img').css('padding',padding);
        }
        e();
        $(window).on("orientationchange, resize",
                function() {
                    e();
                })
 
    });