You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.2 KiB
JavaScript

2 years ago
/**
* 基础JS
*/
var ht = $('html');
var fs = 625;
var ss = 1080;
var htfs;
if (ht.width()<ss) {
orientation(ht);
}
/**
* 横竖撇检测
* @author 鹿文学
*/
function orientation(ht) {
var supportOrientation = (typeof window.orientation == 'number' && typeof window.onorientationchange === 'object');
var init = function() {
var htmlNode = document.body.parentNode,orientation;
var fontSize = ht.width()*fs/ss;
var updateOrientation = function(){
if (supportOrientation) {
orientation = window.orientation;
switch(orientation) {
case 90:fontSize = ht.width()*fs/ss/1.77777;break;
case -90:
fontSize = ht.width()*fs/ss/1.77777;break;
}
} else {
if(window.innerWidth>window.innerHeight) {
fontSize = ht.width()*fs/ss/1.77777;
} else {
fontSize = ht.width()*fs/ss;
}
}
ht.css({'font-size':fontSize+'%'});htfs = parseFloat(ht.css('font-size'));
}
if (supportOrientation) {
window.addEventListener('orientationchange',updateOrientation,false);
} else{
window.addEventListener('resize',updateOrientation,false);
}
updateOrientation();
}
window.addEventListener('DOMContentLoaded',init,false);
}
$(document).ready(function(){
$(window).resize(function(){
if (ht.width()<ss) {
orientation(ht);
}
});
});
/*
* 检测手机PC
* @author lwx
*/
var browser = {
versions:function(){
var u = navigator.userAgent,app=navigator.appVersion;
return {
trident:u.indexOf('Trident')>-1,/*IE*/
presto:u.indexOf('Presto')>-1,/*opera*/
webkit:u.indexOf('AppleWebKit')>-1,/*apple google*/
gecko:u.indexOf('Gecko')>-1 && u.indexOf('KHTML')==-1,/*firefox*/
mobile:!!u.match(/AppleWebKit.*Mobile.*/)||!u.match(/AppleWebKit/),/*移动*/
ios:!!u.match(/\(i[^;]+;( U;)?CPU.+Mac OS X/),/*ios*/
android:u.indexOf('Android')>-1 || u.indexOf('Linux')>-1,/*android uc*/
iPhone:u.indexOf('iPhone')>-1|| u.indexOf('Mac')>-1,/*iPhone QQHD*/
iPad:u.indexOf('iPad')>-1,/*iPad*/
webApp:u.indexOf('Safari')==-1,
weixin: u.indexOf('MicroMessenger') > -1, //是否微信
qq:u.indexOf('QQ') > -1,
};
}(),
language:(navigator.browserLanguage||navigator.language).toLowerCase(),
}