I have a div and when I click it jquery adds a class which starts an animation running. When the animation stops (after 3 seconds) I want the class to be removed, so that when the div is clicked on again the animation will start over.
This is only testing and only Chrome browser at the moment.
Here is my CSS3:
.spin360
{
-webkit-animation-name: spin;
-webkit-animation-duration: 3s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes spin
{
0% { -webkit-transform: rotateX(0); }
100% { -webkit-transform: rotateX(-360deg); }
}
Here is my script:
<script type="text/javascript">
$(document).ready(function () {
$('#spinButton').click(function () {
$('#shape').addClass('spin360');
});
});
</script>
Here is what I’ve tried:
<script type="text/javascript">
$(document).ready(function () {
$('#spinButton').click(function () {
$('#shape').addClass('spin360').on('webkitAnimationEnd', function () {
$('#shape').removeClass('spin360');
});
});
});
</script>
And
<script type="text/javascript">
$(document).ready(function () {
$('#spinButton').click(function () {
$('#shape').addClass('spin360');
});
$('#spinButton').addEventListener('webkitAnimationEnd', function (e) {
$('#shape').removeClass('spin360');
});
});
</script>
In all cases – my animation runs on the first click, but not subsequent clicks.
I was using an older version of jquery.
I updated to 1.8.0 and it works.