// window.onscroll窗口添加滚动条事件
function scrollBottom(){
var thisBottom=0;
if(getScrollHeight() == getDocumentTop() + getWindowHeight()){
thisBottom=1;
}
return thisBottom;
}
//(浏览器窗口上边界内容高度)
function getDocumentTop() {
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if (document.body) {
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
// console.log("scrollTop:"+scrollTop);
return scrollTop;
}
//可视窗口高度(屏幕可以看见的高度)
function getWindowHeight() {
var windowHeight = 0;
if (document.compatMode == "CSS1Compat") {
//IE8及以下在标准模式下
windowHeight = document.documentElement.clientHeight;
} else {
windowHeight = document.body.clientHeight;
}
// console.log("windowHeight:"+windowHeight);
return windowHeight;
}
//滚动条滚动高度(即整个网页的高度)
function getScrollHeight() {
var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
if (document.body) {
bodyScrollHeight = document.body.scrollHeight;
}
if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight;
}
var brand = judgeBrand(navigator.userAgent.toLowerCase());
if(brand=='huawei'){
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight-5 : documentScrollHeight-5;
}else{
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
}
// scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
// console.log("scrollHeight:"+scrollHeight);
return scrollHeight;
}
function judgeBrand(sUserAgent) {
// 判断具体机型华为P20
// var HuaweiP20='Mozilla/5.0 (Linux; Android 8.1; EML-AL00 Build/HUAWEIEML-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.143 Crosswalk/24.53.595.0 XWEB/358 MMWEBSDK/23 Mobile Safari/537.36 MicroMessenger/6.7.2.1340(0x2607023A) NetType/4G Language/zh_CN'
// var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
// if (sUserAgent=HuaweiP20) {
// return 'huaweiP20';
// }
// 判断华为机型
var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
if(isHuawei){
return 'huawei';
}
}
华为手机像素差:
https://blog.csdn.net/zhou_w_x/article/details/106123865
常见的useragent
https://blog.csdn.net/weixin_33721344/article/details/93860512