首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果div可见

如果div可见
EN

Stack Overflow用户
提问于 2014-12-23 19:05:43
回答 3查看 694关注 0票数 13

我使用的是Popcorn.js,它创建了以下HTML代码:

代码语言:javascript
复制
<div id="row-1">
    <div style="display: none;">Hello</div>
</div>

但是现在,当.myClass中的div是display: inline时,我尝试使用jQuery向#row1添加/删除#row1

我尝试过.height().lenght().width() (但是这个不起作用,因为div的宽度总是1246px)

任何帮助都将不胜感激!

** 编辑 **

整个HTML代码:

代码语言:javascript
复制
<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>
EN

回答 3

Stack Overflow用户

发布于 2014-12-23 19:08:07

jQuery有选择器可见,所以您可以检查.is(':visible')

票数 12
EN

Stack Overflow用户

发布于 2014-12-23 19:27:34

要查看子div是否可见,可以执行以下操作-

$('#row-1').children().is(':visible') !$(‘#row-1’).children().is(‘:隐藏’) $(‘#行-1’).children().css(‘display’) == 'none‘

但要回答你的问题,你可以这样做-

如果你想找display: inline,你可以做以下-

$('#row-1').children().filter('divstyle*=display: inline').addClass('myClass')

如果您希望查看它是否可见,然后添加/删除类,则可以执行以下操作-

$('#row-1').children().filter(':hidden').addClass('myClass') //或removeClass

票数 4
EN

Stack Overflow用户

发布于 2014-12-23 19:11:47

因为第一个div有一个id,所以我们可以使用它来获取它的第一个子节点,并检查该子元素的显示值是否等于内联。

代码语言:javascript
复制
// pure javascript

if (document.getElementById('row-1').firstChild.style.display === 'inline') {
    // add/remove class
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27626483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档