+ 2
Trigger An Event Multiple times
How do I trigger the event more than once. This is the code: //HTML <html onclick="clicked()"> <body> <div id="wraps"> <div class="head"></div> <div class="body"></div> <div class="leftH"></div> <div class="rightH"></div> </div> <script> function clicked() { var jump = document.getElementById("wraps"); jump.classList.add("wraps"); } </script> </body> </html> //CSS .wraps { animation: jump 0.4s linear forwards; } @keyframes jump { 0%{top: 263px;} 60%{top: 200px;} 100%{top: 263px;} } Hope someone help me out
12 Answers
+ 3
Ibrahim Yusuf hi,
Not sure this is the most efficient way to do it, but it will works :
As it seems once you first click, the class is added as expected but then as the class is already set, the following clicks kind of ignore the repetition. To go around that you can add, in your function after the jump.classList.add();
setTimeout(()=>{
jump.classList.remove("wraps")},300);
+ 3
https://code.sololearn.com/W69uG45Pn3Cf/?ref=app
Ibrahim Yusuf this might help you to learn setInterval.
+ 3
EmmanueLZ. It works, That was great Idea, Thank youuu!
+ 2
Using setInterval đ
+ 2
Ibrahim Yusuf but you have already completed the JavaScript course
+ 1
Namit Jain Yeah, but I mean I'm still practicing.
+ 1
RKK Thanks. Actually I know how to use setInterval but I don't it can help with my code. let me share it so u can see
+ 1
https://code.sololearn.com/W7fHcSJoLtWg/?ref=app
The click triggers once
+ 1
Namit Jain Thank you
+ 1
hi
0
@Namit Jain Can u please code it. I'm still learning javascript
0
You can take idea from this code
Because the gravity in your code is not working correctly
https://code.sololearn.com/WmM0Du149I4z/?ref=app