1

Does anyone know why this isn't working? I just want my button to stop the background animation when it is clicked. Please help me.

$(document).ready(function(){
    $("#togglebackgroundbutton").click(function(){
        $("-webkit-keyframes bg").toggleclass("paused");
    });
});

</script>
<style>
    body {
        background-color:green;
        -webkit-animation-name:bg;
        -webkit-animation-iteration-count:infinite;
        -webkit-animation-duration:2s;
    }

    @-webkit-keyframes bg {
        from{background-color:green;}
        50%{background-color:yellow;}
        to{background-color:green;}
    }

    .paused {
        -webkit-animation-play-state:paused;
    }
3
  • 1
    I don't know about you, but I've never heard of a <-webkit-keyframes><bg>Content</bg></-webkit-keyframes> structure before :p Commented Feb 2, 2014 at 18:57
  • 1
    You cannot select CSS Styles, you have to select the element and toggle the class on/off of that. Commented Feb 2, 2014 at 18:57
  • check your specificity. Try changing .paused to an ID Commented Feb 2, 2014 at 19:08

1 Answer 1

1
$(document).ready(function(){
    $("#togglebackgroundbutton").click(function(){
        $("body").toggleClass("paused");
    });
});

You should toggle class on body. Also its toggleClass and not toggleclass

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.