परिचय
CSS एनिमेशन transform फंक्शन्स को संयोजित, रोटेट, और ट्रांसलेट करके एलिमेंट्स को विभिन्न तरीकों से ट्रांसफॉर्म करने में हमारी मदद कर सकते हैं।
उदाहरण: CSS ट्रांसफॉर्म के साथ सर्कुलर मोशन
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 8%;
width: 35px;
height: 35px;
border-radius: 5px;
background: red;
animation: move 3s infinite linear;
}
@keyframes move {
0% {
transform: rotate(0deg) translateX(40px) rotate(0deg);
}
100% {
transform: rotate(360deg) translateX(40px) rotate(-360deg);
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
तकनीक समझाया गया
यह "डबल रोटेशन" तकनीक का उपयोग करता है:
rotate(0deg → 360deg)— एलिमेंट को केंद्र के चारों ओर घुमाता हैtranslateX(40px)— एलिमेंट को केंद्र से 40px दूर ले जाता है (त्रिज्या)rotate(0deg → -360deg)— एलिमेंट को काउंटर-रोटेट करता है ताकि यह सीधा रहे
परिणाम: एलिमेंट एक सर्कल में घूमता है जबकि अपनी दिशा बनाए रखता है।
मॉडर्न विकल्प: CSS offset-path (मोशन पाथ)
<!DOCTYPE html>
<html>
<head>
<style>
.orbit {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(135deg, #667eea, #764ba2);
offset-path: path('M 200,200 m -100,0 a 100,100 0 1,0 200,0 a 100,100 0 1,0 -200,0');
animation: orbit 4s linear infinite;
}
@keyframes orbit {
0% { offset-distance: 0%; }
100% { offset-distance: 100%; }
}
.container {
width: 400px;
height: 400px;
margin: 2rem auto;
border: 2px dashed #cbd5e1;
border-radius: 50%;
position: relative;
}
</style>
</head>
<body>
<div class="container">
<div class="orbit"></div>
</div>
</body>
</html>
उन्नत: एकाधिक ऑर्बिटिंग एलिमेंट्स
<!DOCTYPE html>
<html>
<head>
<style>
.solar-system {
width: 500px;
height: 500px;
margin: 2rem auto;
position: relative;
border: 1px solid #334155;
border-radius: 50%;
background: radial-gradient(circle at center, #1e293b, #0f172a);
}
.sun {
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 60px; height: 60px;
border-radius: 50%;
background: radial-gradient(circle at 30% 30%, #fde047, #f59e0b);
box-shadow: 0 0 40px #fde047, 0 0 80px #f59e0b;
z-index: 10;
}
.planet {
position: absolute;
top: 50%; left: 50%;
border-radius: 50%;
transform-origin: center center;
animation: orbit linear infinite;
}
.mercury { width: 10px; height: 10px; background: #94a3b8; animation-duration: 3s; margin: -5px; }
.venus { width: 16px; height: 16px; background: #fbbf24; animation-duration: 5s; margin: -8px; }
.earth { width: 18px; height: 18px; background: #3b82f6; animation-duration: 8s; margin: -9px; }
.mars { width: 12px; height: 12px; background: #ef4444; animation-duration: 12s; margin: -6px; }
@keyframes orbit {
from { transform: translate(-50%, -50%) rotate(0deg) translateX(120px) rotate(0deg); }
to { transform: translate(-50%, -50%) rotate(360deg) translateX(120px) rotate(-360deg); }
}
/* अलग-अलग कक्षाओं के लिए ट्रांसलेट X एडजस्ट करें */
.venus { animation-duration: 5s; }
.earth { animation-duration: 8s; }
.mars { animation-duration: 15s; }
</style>
</head>
<body>
<div class="solar-system">
<div class="sun"></div>
<div class="planet mercury"></div>
<div class="planet venus"></div>
<div class="planet earth"></div>
<div class="planet mars"></div>
</div>
</body>
</html>
ब्राउज़र सपोर्ट
- ट्रांसफॉर्म दृष्टिकोण: सभी मॉडर्न ब्राउज़र (IE10+)
- offset-path: Chrome 69+, Firefox 72+, Edge 79+, Safari 16.4+