//判断是否为移动端运行环境
var mob='';
if(/AppleWebkit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if (window.location.href.indexOf("?mobile")<0) {
try {
mob = 'true';
}
catch(e){}
}
}
// 获取链接参数
function getQueryString(name){
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
// 获取页面视口宽高
function getViewRect(){
var pageWidth = window.innerWidth,
pageHeight = window.innerHeight;
if (typeof pageWidth != 'number') {
if(document.compatMode == 'CSS1Compat'){
pageWidth = document.documentElement.clientWidth;
pageHeight = document.documentElement.clientHeight;
}else{
pageWidth = document.body.clientWidth;
pageHeight = document.body
.clientHeight;
}
}
return {
width: pageWidth,
height: pageHeight
};
}
// 判断横竖屏
function hengshuping(){
if (window.orientation==180||window.orientation==0) {
var h = getViewRect().height;
$('html').css('minHeight',h+'px');
}
if (window.orientation==90||window.orientation==-90) {
var h = getViewRect().height;
$('html').css('minHeight',h+'px');
}
};
if (mob=='true') {
$(window).on('orientationchange',function(){
setTimeout(function(){
hengshuping();
},)
});
}
移动端必用js
最新推荐文章于 2022-04-02 21:29:25 发布