jquery:this.not(':animated')&& that.is(':visible')不遵循规则,语法问题?只有几行代码

and*_*ick 5 javascript jquery if-statement visible animated

当我点击#button它时,它仍在静止'do something',即使.wrapper是动画并且.wrapper span不可见.所以它不遵守规则.怎么了?

$('#button').click(function(){
  if(
    $('.wrapper').not(':animated') && $('.wrapper span').is(':visible')
  ) {
    //do something
  }
})
Run Code Online (Sandbox Code Playgroud)

Nic*_*ale 6

没有if语句,这有点清晰.工作演示

$('#button').click(function(){ 
    $('.wrapper').filter(':animated').text("animating...");
    $('.wrapper').filter(':not(:animated)').text("not animating...");
}) 
Run Code Online (Sandbox Code Playgroud)


net*_*tos 4

在这里你有一个working demo

$('#button').click(function(){
if(    $('.wrapper:animated').length>0)
{
 $(".wrapper").text("animating")   ;
}
  if(
    $('.wrapper:animated').length<1) {
 $(".wrapper").text("not animating")   ;
  }
})
Run Code Online (Sandbox Code Playgroud)