getElementRect: function (element) {
var rect = element.getBoundingClientRect() // 距离视窗的距离
var top = document.documentElement.clientTop ? document.documentElement.clientTop : 0 // html元素对象的上边框的宽度
var left = document.documentElement.clientLeft ? document.documentElement.clientLeft : 0
return {
top: rect.top - top,
bottom: rect.bottom - top,
left: rect.left - left,
right: rect.right - left
}
}
setValue: function () {
var that = this;
var $tabCon = document.getElementById('tabCon');
var windowH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight // 浏览器高度兼容写法
window.onscroll = function () {
var obj = that.getElementRect($tabCon);
if ((obj.top < 0)) {
that.showFixedTab = true;
} else {
that.showFixedTab = false;
}
}
}
showFixedTab 显示固定导航栏