css()
methodYou can use the jQuery css()
method in combination with the CSS3 animation-play-state
property to play and stop CSS animations in the middle of a cycle.
Let's take a look at the following example to understand how it basically works:
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Play and Stop CSS Animation</title>
<style>
.animated {
height: 200px;
margin: 10px 0;
background: url("smiley.png") no-repeat left center #e4eacf;
-webkit-animation: test 4s infinite; /* Chrome, Safari, Opera */
animation: test 4s infinite;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes test {
50% {background-position: right center;}
}
/* Standard syntax */
@keyframes test {
50% {background-position: right center;}
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$(".play-animation").click(function(){
$(".animated").css("animation-play-state", "running");
});
$(".stop-animation").click(function(){
$(".animated").css("animation-play-state", "paused");
});
});
</script>
</head>
<body>
<div class="animated"></div>
<button type="button" class="play-animation">Play Animation</button>
<button type="button" class="stop-animation">Stop Animation</button>
<p><strong>Warning:</strong> CSS Animations do not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel Eloquent One to One Polymorphic Relationship Tutorial with Example
While designing database structure, you...How to Run Angular project on different port other than 4200
Sometimes you need to run two different...Laravel 8 Create Multi Language Website
Laravel provides easy way to create mult...How to Check If an Input Field is Empty Using jQuery
Use the jQuery val() Method...How to Set or Unset a Cookie with jQuery
Use the JS document.cookie Property Y...