女猿1024

齐刘海适配

2020-04-30  本文已影响0人  代艳霞
<script>
            //需要插入在<head>标签内在所有脚本之前执行
            (function(win) {
                if (!win.addEventListener) return;
                var html = document.documentElement;

                function setFont() {
                    function setRem() {
                        var cliWidth = html.clientWidth;
                        var w = document.documentElement.clientWidth,
                            h = document.documentElement.clientHeight;
                        var val = 750;
                        switch (window.orientation) {
                            case 0:
                                //刘海在上边
                                // displayStr = "direction_por";
                                break;
                            case -90:
                                //刘海在右边
                                // displayStr = "direction_land_ops";
                                val = 1334;
                                break;
                            case 90:
                                //刘海在左边
                                // displayStr = "direction_land";
                                val = 1334;
                                break;
                            case 180:
                                //刘海在下边
                                // displayStr = "direction_por_ops";
                                break;
                            default:
                                if (w > h) {
                                    val = 1334;
                                }
                        }
                        html.style.fontSize = 100 * (cliWidth / val) + 'px';
                    }
                    setRem();
                    setTimeout(function() {
                        setRem();
                    }, 300);
                }
                win.addEventListener('resize', setFont, false);
                setFont();
            })(window);
        </script>
上一篇下一篇

猜你喜欢

热点阅读