slideToggle和:visible [英] slideToggle and :visible

查看:108
本文介绍了slideToggle和:visible的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用sliderToggle方法时,:visible表达式似乎永远不会返回除true以外的任何内容.

When using the sliderToggle method, the :visible expression never seems to return anything other than true.

如果我手动将show/hide:visible表达式结合使用,它将很好地工作.

If I manually use show/ hide in conjunction with :visible expression it'll work just fine.

失败的示例:

jQuery(".fileNode .nodeExpander").click(function() {
    var notes = jQuery(this).parent().siblings(".fileNotes");
    notes.slideToggle ("fast");

    var isVisible = notes.is(":visible"); // Always returns true...

    // Do stuff based on visibility...
});

工作的示例:

jQuery(".fileNode .nodeExpander").click(function() {
    var notes = jQuery(this).parent().siblings(".fileNotes");
    var isVisible = notes.is(":visible");

    if (isVisible)
        notes.hide("fast");
    else
        notes.show("fast");

    // Do stuff based on visibility...
});

一些html:

<ul>
    <li class="fileNode">
        <img src="<%= Url.Content ("~/Images/Collapse.png") %>" alt="<%= UIResources.CollpaseAltText %>" class="nodeExpander" />
    </li>
    <li class="fileLink">
        <%= Html.ActionLink (file.Name, "Details", new { id = file.FileId }) %>
    </li>
    <li class="fileNotes">
        <%= file.Description %>
    </li>
</ul>

我假设slideToggle不执行show/hide-我还可以检查其他内容吗?

I'm assuming that the slideToggle doesn't do a show/ hide - is there something else I can check?

我在Firefox 3.5,IE 7、8和Chrome 4中尝试过...所有结果都相同.

I've tried in Firefox 3.5, IE 7, 8 and Chrome 4...all with the same results.

谢谢, K

推荐答案

在slideToggle处于过渡阶段的过程中,您的第一个(非工作状态)代码片段将测试:visible(更准确地说,它是在过渡开始后进行测试的) ).无论您要打开还是关闭,过渡过渡状态均为:visible-因此您始终会得到true.

Your first (non-working) code fragment will be testing :visible while slideToggle is mid-transition (more precisely, it tests it just after the transition starts.) Regardless of whether you're opening or closing, the mid-transition state will be :visible - so you always get true.

在致电slideToggle

这篇关于slideToggle和:visible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆