参见英文答案 >
How do I check if an element is hidden in jQuery?53个
我正在使用Popcorn.js并创建以下HTML代码:
我正在使用Popcorn.js并创建以下HTML代码:
<div id="row-1">
<div style="display: none;">Hello</div>
</div>
但是现在我正在尝试使用jQuery添加/删除.myClass到.test,当#row1中的div显示为:inline时.
我试过.height(),. lenght()和.width()(但是这个不起作用,因为div的宽度总是1246px)
任何帮助将不胜感激!
**编辑**
整个HTML代码:
<html>
<head>
<script src="http://popcornjs.org/code/dist/popcorn-complete.min.js"></script>
<script src="js/jquery-1.11.2.min.js"></script>
<style>
.myClass{
background: yellow !important;
}
</style>
<script>
// ensure the web page (DOM) has loaded
document.addEventListener("DOMContentLoaded",function () {
// Create a popcorn instance by calling the Youtube player plugin
var example = Popcorn.youtube(
'#video','https://www.youtube.com/embed/w9l4v1s9148?controls=1' );
example.footnote({
start: 1.2,end: 1.7,text: "Hello",target: "row-1"
});
example.footnote({
start: 1.7,end: 3.2,text: "boys and girls",target: "a2"
});
example.footnote({
start: 3.2,end: 4.8,text: "my name is FatLip,",target: "a3"
});
example.footnote({
start: 4.8,end: 7,text: "and this is my friend,Simon the Salmon.",target: "a4"
});
},false);
</script>
</head>
<body>
<div id="video" style="width: 360px; height: 300px;" ></div>
<div id="row-1"></div>
<div id="a2"></div>
<div id="a3"></div>
<div id="a4"></div>
<div class="test" style="width: 10px; height: 10px; background: black;"></div>
</body>
</html>
解决方法
jQuery有选择器
visible所以你可以检查.is(‘:visible’)