我使用document.body.getBoundingClientRect().right来发现顶部导航中的所有元素都将从视图中消失,以便将它们隐藏起来,并将它们放在“More”下拉列表中。但是这个函数在safari中似乎不起作用。有没有其他方法可以替代这个函数,或者有什么方法可以在safari中修复它?
var windowRightOffset = document.body.getBoundingClientRect().right,
elementHiddenFlag = false;
$(".headerNav").find("li").each(function() {
if ($(this).className !== 'more') {
var elemRightOffset = $(this).find("a")[0].getBoundingClientRect().right;
if (elemRightOffset > windowRightOffset) {
$(this).hide();
elementHiddenFlag = true;
$(".more .moreNavItems-content").append($(this).html());
}
}
});发布于 2017-08-02 22:24:56
发布于 2019-06-03 21:48:03
好的,开始吧:-)
function getBounding(name,index){
this.ele = document.querySelectorAll(name)[index];
this.y= this.ele.offsetTop;
this.x= this.ele.offsetLeft;
this.coordinates();
}
getBounding.prototype.coordinates = function(){
if( this.ele.localName != "body"){
this.ele = this.ele.offsetParent;
this.y += this.ele.offsetTop;
this.x += this.ele.offsetLeft;
this.coordinates();
} else {
return({x:this.x,y:this.y});
}
}新建getBounding(".-img",0)
https://stackoverflow.com/questions/45463348
复制相似问题