0

I am trying to use addclass and hasclass to add animate.css animation to the division class.

<section class="main active">
 ...
</section>
<section class="aboutus">
    <h1>About Us</h1>
    <p class="aboutus-text">
    Text
    </p>
</section>

The above is the HTML code that I am trying to animate.

So when scrolled to aboutus section, active will be removed from main and added to aboutus section.

I tried using this to detect and add animation when active exist in aboutus section.

if($("section.aboutus").hasClass('active')) {
    $(".aboutus-text").addClass("animated fadeIn");
};

It is not working. I tried to see if addClass is working properly by removing the if statement, 'animated fadeIn' is added to aboutus-text.

Anyone can tell me how do I do this? Because I only want the animation to start when aboutus is active.

12
  • looks like your code is executed before the code that is adding the class is executed Commented Oct 8, 2014 at 2:41
  • add console.log($("section.aboutus").attr('class')) just before the if condition to see what are the classes present Commented Oct 8, 2014 at 2:42
  • Can you make a jsfiddle of your code? Commented Oct 8, 2014 at 2:44
  • @ArunPJohny My console shows 'aboutus section' Commented Oct 8, 2014 at 2:56
  • @YoannM I am using this js call onepagescroll also.. so I have no idea how to customize jsfiddle to have it.. Commented Oct 8, 2014 at 2:57

1 Answer 1

1

The plugin has an afterMove() callback, you need to use it

$(".main").onepage_scroll({
    easing: "ease",
    animationTime: 1000,
    afterMove: function () {
        if ($("section.aboutus").hasClass('active')) {
            $(".aboutus-text").addClass("animated fadeIn");
            $("section.aboutus").css({
                'display': 'block'
            });
        };
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.