默认宽屏,使用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();