jquery: this.not (':animated') && that.is (':visible') not following the rules, syntax problem? only few lines of code

孤人 提交于 2019-12-19 19:34:15

问题


when i click on #button, it's stilling doing the 'do something', even though .wrapper is animating and .wrapper span is not visible. so it's not following the rules. what's wrong?

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

回答1:


Here you have a working demo:

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



回答2:


This is a bit cleaner without the if statements. working demo

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



来源:https://stackoverflow.com/questions/4012218/jquery-this-not-animated-that-is-visible-not-following-the-rules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!