(function(doc, win) { var screenWidth = 0, size = 'M', root = doc.documentElement; if (window.screen && screen.width) { screenWidth = screen.width; if (screenWidth > 1920) { // 超大屏,例如iMac size = 'L'; } else if (screenWidth < 480) { // 小屏,如手机 size = 'S'; } } // 标记CSS root.className = size; // 标记JS win.SIZE = size; })(document, window);
.S .example { /* 移动端的样式 */ }
if (window.SIZE == 'S') { // 移动端的处理 } else { // 桌面端的处理 }
本文出自:http://www.zhangxinxu.com/wordpress/?p=5416