PC宽窄屏适配

默认宽屏,使用w1024适配小屏

    var small = 1245;
    var middle = 1345;
    var timer = null;
    var $html = $('html');
    
    function checkHtmlSize() {
        var width = document.documentElement.clientWidth;
        if (width < small) {
            $html.removeClass('w1280');
            $html.addClass('w1024');
        }
        else if (width > small && width < middle) {
            $html.removeClass('w1024');
            $('html').addClass('w1280');
        }
        else {
            $html.removeClass('w1024');
            $html.removeClass('w1280');
        }
    }
    $(window).resize(function(){
        clearTimeout(timer);
        // 函数节流
        timer = setTimeout(checkHtmlSize, 50);
    });
    checkHtmlSize();
此条目发表在CSS, HTML, JavaScript分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注