JQ监听手机横竖屏/JS监听手机横竖屏
JQ监听
//监听屏幕旋转 $(window).on('orientationchange', function() { var $el = $("body"); // 需要重新获得宽和高的元素 newWidth = $el.width(); // 新的宽 newHeight = $el.height(); // 新的高 console.log(newWidth+"新宽"); console.log(newHeight+"新高"); });
JS监听
//监听横竖屏 var evt = "onorientationchange" in window ? "orientationchange" : "resize"; window.addEventListener(evt,resize,false); function resize(fals) { if(window.orientation == 0 || window.orientation == 180) { alert("旋转1"); }else { alert("旋转2"); } } resize(true);