سؤال

عند استخدام sliderToggle الطريقة ، :visible لا يبدو أن التعبير لا يعيد أي شيء سوى صحيح.

إذا استخدمت يدويًا show/ hide بالتزامن مع :visible التعبير سوف يعمل بشكل جيد.

مثال على خزي:

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 - هل هناك شيء آخر يمكنني التحقق منه؟

لقد حاولت في Firefox 3.5 و IE 7 و 8 و Chrome 4 ... كل ذلك مع نفس النتائج.

شكرا ، ك

هل كانت مفيدة؟

المحلول

سيتم اختبار جزء الكود الأول (غير العاملة) :visible على الرغم من أن Slidetoggle هو منتصف الانتقال (بدقة أكثر ، فإنه يختبره بعد انتقاله مباشرة.) بغض النظر عما إذا كنت تفتح أو تغلق ، ستكون حالة الانتقال المتوسطة :visible - لذلك تحصل دائما true.

حاول التحقق .is(":visible") قبل الاتصال slideToggle

نصائح أخرى

حاول إضافة معالج.

notes.slideToggle ("fast", function() { 
  var isVisible = notes.is(":visible");
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top