jQuery - If element has class do this

后端 未结 1 1515
时光说笑
时光说笑 2020-12-04 09:41

I need an jQuery script that will see if any element has an specific class and do an action like change position.

This is the way, but I don`t think this will work.<

相关标签:
1条回答
  • 2020-12-04 10:01

    First, you're missing some parentheses in your conditional:

    if ($("#about").hasClass("opened")) {
      $("#about").animate({right: "-700px"}, 2000);
    }
    

    But you can also simplify this to:

    $('#about.opened').animate(...);
    

    If #about doesn't have the opened class, it won't animate.

    If the problem is with the animation itself, we'd need to know more about your element positioning (absolute? absolute inside relative parent? does the parent have layout?)

    0 讨论(0)
提交回复
热议问题