【问题标题】:Jquery fadein and fadeout script not workingJquery淡入和淡出脚本不起作用
【发布时间】:2009-10-07 09:11:51
【问题描述】:

如果 Box 没有动画并且显示值为 none,则当单击 class="display" 时,此函数应该在 id="Box" 中淡入淡出;如果 #Box 的显示值不是 none,则应使用 fadeOut。怎么了?

$(document).ready(function() {
    $('.display').click(function() {
        var currentDisplayValue = $('#Box').css('display');

        if (':animated') {
        stop()
        };

        else if (currentDisplayValue == 'none') {
            $('#Box').fadeIn("slow");
        };

        else {
            $('#Box').fadeOut("slow");
        };
    });

谢谢

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    试试:

    $(function() {
      $(".display").click(function() {
        var box = $("#Box");
        if (box.is(":animated")) {
          box.stop();
        } else if (box.is(":hidden") {
          box.fadeIn("slow");
        } else {
          box.fadeOut("slow");
        }
      });
    });
    

    你有一些语法错误(例如花括号后的分号),stop() 需要应用于 jquery 集。最后,不要像现在这样检查当前的显示 CSS 值。请改用:hidden 选择器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      相关资源
      最近更新 更多