当超过0%的元素在视口/窗口中时返回true
Return true when more than 0% of element is in viewport / window
因此,当作为参数给定的元素完全在视口/窗口中时,下面的代码返回true。
当元素的任何一位或任何超过0%的元素在视口中时,我如何更改它,使其返回true?
function isElementInViewport(el){
var rect = el.getBoundingClientRect();
return(
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document. documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document. documentElement.clientWidth)
);
}
交换top
和bottom
,以及交换left
和right
。
function isElementInViewport(el){
var rect = el.getBoundingClientRect();
return rect.bottom >= 0 &&
rect.right >= 0 &&
rect.top <= (window.innerHeight || document. documentElement.clientHeight) &&
rect.left <= (window.innerWidth || document. documentElement.clientWidth);
}
此处演示:jsfiddle.net/w7ApB
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 防止Iframe窗体在新窗口中打开
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 调整窗口大小时,可拖动的对象会出现在容器外部
- Javascript排序的图像弹出窗口..可以't单独弹出
- 窗口大小html css
- 弹出窗口出现,然后退出
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- AngularJS-使用'true'属性
- Javascript更新孙窗口中的表单元素
- 如何在选项卡上定义属性'的主窗口对象
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- (窗口中的'ontouchstart')返回true,但没有触摸事件
- 根据在弹出窗口中单击的按钮返回 true 或 false
- 为什么`'onhashchange'在IE8的IE7兼容模式的窗口“return”true中
- 当超过0%的元素在视口/窗口中时返回true
- 删除browser.ignoreSynchronization=true causes;在窗口上找不到角度”;
- 窗口.关闭 IE9 在窗口仍打开时报告 true
- 如果我重写窗口.javascript中的onerror应该返回true还是false