【问题标题】:jQuery visible targeting issuejQuery 可见定位问题
【发布时间】:2010-09-02 21:13:03
【问题描述】:

我已经制作了这个脚本,让您可以使用 jQuery 浏览多个 div,但是如果显示第 6 个 div 并且使用 .is(":visible") 没有给出,我想对父级进行 css 更改祝我好运。

$(document).ready(function() {
  /* Set the frame to #sf1 */
    $('#sf2, #sf3, #sf4, #sf5, #sf6').hide(); 
  /* Slide Animation for Next Slides */
    $('.nextbutton').click(function() { 
      $(this).parents('li').fadeOut(300);
      $(this).parents('li').next().fadeIn(300);
      if ($('#sf6').is(":visible") == "true") {
        alert('that just happened');
        $('#stepForm').css('height', 'auto !important');
      }
    }); 
  /* Slide Animation for Previous Slides */
    $('.prevbutton').click(function() { 
      $(this).parents('li').prev().fadeIn(300);
      $(this).parents('li').fadeOut(300);
    }); 
}); 

【问题讨论】:

    标签: javascript jquery html transitions


    【解决方案1】:

    你应该改变

    if ($('#sf6').is(":visible") == "true") {
    

    只是

    if ($('#sf6').is(":visible")) {
    

    【讨论】:

      【解决方案2】:

      为什么不测试可以使其可见的 css 属性...

      var dis = $('#sf6').css('display');
      if (dis == 'visible' || dis == 'block'){
        // do something
      }
      

      【讨论】:

        【解决方案3】:

        您可以通过像这样测试长度属性在一个选择器中捕获所有内容:

        if ( $('#sf6:visible').length ) {...
        

        这样应该会快一点。只是以为我会把它扔在那里。 :o)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-10-29
          • 1970-01-01
          • 1970-01-01
          • 2014-12-20
          相关资源
          最近更新 更多