cssanimation
Fri Nov 01 2024 13:56:29 GMT+0000 (Coordinated Universal Time)
Saved by
@abhigna
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive CSS3 Animations</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f4f4f4;
margin: 0;
}
.box {
width: 100px;
height: 100px;
background-color: #3498db;
transition: transform 0.3s, background-color 0.3s;
}
.box:hover {
background-color: #2980b9;
transform: scale(1.1);
}
button {
margin-top: 20px;
padding: 10px 20px;
background-color: #e67e22;
color: white;
border: none;
cursor: pointer;
}
.move {
animation: move 1s forwards;
}
@keyframes move {
from { transform: translateX(0); }
to { transform: translateX(200px); }
}
</style>
</head>
<body>
<div class="box" id="box"></div>
<button id="moveBtn">Move Box</button>
<script>
const box = document.getElementById('box');
const moveBtn = document.getElementById('moveBtn');
moveBtn.addEventListener('click', () => {
box.classList.toggle('move');
});
</script>
</body>
</html>
content_copyCOPY
Comments