Jquery检查元素在视口中是否可见 [英] Jquery check if element is visible in viewport
本文介绍了Jquery检查元素在视口中是否可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检查div类media是否在浏览器可视视口内,而不管窗口滚动位置如何。
Function to check if the div class "media" is within the browsers visual viewport regardless of the window scroll position.
<HTML>
<HEAD>
<TITLE>My first HTML document</TITLE>
</HEAD>
<BODY>
<div class="main">
<div class="media"></div>
</div>
</BODY>
</HTML>
尝试使用此插件 https://github.com/customd/jquery-visible 使用此功能,但
我不知道如何使其工作。
Trying to use this plugin https://github.com/customd/jquery-visible with this function but I don't know how to make it work.
$('#element').visible( true );
推荐答案
嗯,你是怎么试图让它起作用的?根据该插件的文档, .visible()
返回一个布尔值,指示元素是否可见。所以你会这样使用它:
Well, how did you try to make it work? According to the documentation for that plugin, .visible()
returns a boolean indicating if the element is visible. So you'd use it like this:
if ($('#element').visible(true)) {
// The element is visible, do something
} else {
// The element is NOT visible, do something else
}
这篇关于Jquery检查元素在视口中是否可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文