if语句不能触发jquery

时间:2014-11-18 19:12:23

标签: javascript jquery if-statement

我尝试在每个#no-noti的父级div消失后,使用if语句但没有运气时显示.noti-button。代码有什么问题吗?

$(document).ready(function(){

  $(".noti-button").on("click", function(){
    $(this).parent().fadeOut("slow")
  });

  if( $(".noti-box-pt").css("display") === "none" ){
      $("#no-noti").fadeIn("slow");
  }

});

2 个答案:

答案 0 :(得分:1)

我想你想使用fadeOut的回调。一旦fadeOut完成,它就会被触发。

$(document).ready(function(){

  $(".noti-button").on("click", function(){
    $(this).parent().fadeOut("slow", function() {
       $("#no-noti").fadeIn("slow");
    });
  });
});

修改另外,请考虑将if语句更改为:

if( $(".noti-box-pt").is(':hidden') ) {
    ...
}

答案 1 :(得分:0)

您需要在点击处理程序中触发fadeIn() fadeOut()个语句。

http://jsfiddle.net/tnjpe1cw/

$(document).ready(function(){

  $(".noti-button").on("click", function(){
    $("#no-noti").fadeIn("slow");
  });

});

这使您可以控制动画。目前,if语句只会在页面加载时运行一次,但不会在单击按钮时运行。

希望这有帮助!

相关问题