I've created a simple animation using the jQuery animate() method.
simply when I clicked the button the brown box is animated, then I click it again it should reverse the animation(reset the box position).
when the button is clicked animation happens properly but the reset process is not working.
May I know if is there a way to use toggle() and animate() same time?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<link rel="stylesheet" href="Style.css">
<title>Document</title>
</head>
<body>
<div class="squre"></div>
<div class="main"><h2>Click Me</h2></div>
<script src="attion.js"></script>
</body>
</html>
body{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: tan;
gap: 20px;
}
.main{
text-align: center;
height: 50px;
width: 200px;
cursor: pointer;
border: 1px solid black;
}
.squre{
width: 200px;
height: 200px;
background-color: brown;
position: relative;
left: -200px;
}
$(document).ready(()=>{
$('.main').click(()=>{
$('.squre').animate({
left: '200px',
rotate:'300deg',
width: '20',
height: '20',
},500)
})
})
I've created a simple animation using the jQuery animate() method.
simply when I clicked the button the brown box is animated, then I click it again it should reverse the animation(reset the box position).
when the button is clicked animation happens properly but the reset process is not working.
May I know if is there a way to use toggle() and animate() same time?