Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 18, 2023, 3:41 AM EDT
Hi vamsi try this
.box { width: 100px; height: 100px; background-color: blue; transition: transform 0.3s ease; } .box.clicked { transform: scale(1.2) rotate(45deg); } function animateBox() { var box = document.querySelector('.box'); box.classList.toggle('clicked'); }If u can give more details on what you are expecting ill try a few more
Prathap ReddyRank #230 · 10.8K reputationPosted May 18, 2023, 4:04 AM EDT
Hi Vamsi !
You can go through the below code snippet :
const btn = document.querySelector("button");
btn.addEventListener("click", () => {
const ripple = document.createElement("div");
ripple.classList.add("ripple");
ripple.style.top = btn.offsetTop + "px";
ripple.style.left = btn.offsetLeft + "px";
document.body.appendChild(ripple);
ripple.addEventListener("animationend", () => {
document.body.removeChild(ripple);
});
ripple.animate({
width: btn.offsetWidth,
height: btn.offsetHeight,
borderRadius: "50%",
background: "red",
}, {
duration: 500,
});
});
Vishal JoshiRank #377 · 6.7K reputationPosted May 18, 2023, 7:51 AM EDT
Hello Vamsi,
Please check out the below sample code for js animation.
Animate on click with Javascript! body { margin: 0; } Hello World! Click to Animate function beyblade() { let x = document.getElementById("animate") x.style.marginLeft = "300px" x.style.transition = "1s" }Please share more detail like the case where needed animation so accordingly we can review and use third-party animation or create our own custom animation.
Thanks
Deepak RawatRank #646 · 3.7K reputationPosted May 18, 2023, 8:37 AM EDT
JavaScript animation for an on-click effect using the GSAP (GreenSock Animation Platform) library
Click Animation .box { width: 100px; height: 100px; background-color: #ff6347; cursor: pointer; } const box = document.querySelector('.box'); box.addEventListener('click', function() { // Animate the box when clicked gsap.to(box, { duration: 1, scaleX: 2, scaleY: 2, backgroundColor: '#ffd700', ease: 'power2.out', onComplete: function() { // Reset the box after the animation is complete gsap.to(box, { duration: 1, scaleX: 1, scaleY: 1, backgroundColor: '#ff6347', ease: 'power2.out' }); } }); });