您现在的位置是:首页 > 技术杂文前端杂文
JS动态获取高度
阿龙2021-11-30【前端杂文】人已围观
获取窗口可视范围的高度
function getClientHeight() {
let clientHeight = 0;
if (document.body.clientHeight && document.documentElement.clientHeight) {
clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
}
else {
clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
}
return clientHeight;
}
获取窗口可视范围宽度
function getPageViewWidth() {
let d = document,
a = d.compatMode == "BackCompat" ? d.body : d.documentElement;
return a.clientWidth;
}
获取窗口尺寸
function getViewportOffset() {
if (window.innerWidth) {
return {
w: window.innerWidth,
h: window.innerHeight
}
} else {
// ie8及其以下
if (document.compatMode === "BackCompat") {
// 怪异模式
return {
w: document.body.clientWidth,
h: document.body.clientHeight
}
} else {
// 标准模式
return {
w: document.documentElement.clientWidth,
h: document.documentElement.clientHeight
}
}
}
}
获取滚动条距顶部高度
function getPageScrollTop() {
let a = document;
return a.documentElement.scrollTop || a.body.scrollTop;
}
获取滚动条距左边的高度
function getPageScrollLeft() {
let a = document;
return a.documentElement.scrollLeft || a.body.scrollLeft;
}
Tags:获取高度
很赞哦! ()
上一篇:JS中去除数组中重复对象
下一篇:JS页面自适应
随机图文
CSS盒子水平居中的六种方法
方法一:定位居中.child{position:absolute;top:50%;left:50%;margin-top:-50px;margin-left:-50px;}方法二:margin居中.child{position:absolute;margin:auto;top:0;left:0;riJS将24小时格式转换为12小时
var dt = new Date();var hours = dt.getHours(); // 以24小时格式给出值var minutes = dt.getMinutes() ;var finalTime = "Time - " + hours + ":" + minutes;//finalTime