CSS हमें तत्वों के गुणों के संक्रमण को एनिमेट करने की अनुमति देता है। हम अपने वांछित स्टाइल को परिभाषित करने के लिए animation प्रॉपर्टी का उपयोग करते हैं। हम animation कीवर्ड का उपयोग करके animation-name, animation-duration, animation-iteration-count जैसे गुणों को संयोजित कर सकते हैं।
सिंटैक्स
animation प्रॉपर्टी का सिंटैक्स निम्नानुसार है:
object.style.animation = "name duration timingFunction delay iterationCount direction fillMode playState"
मान
निम्नलिखित मान हैं:
| मान | विवरण |
|---|---|
| animation-name | सेलेक्टर से बांधने के लिए कीफ्रेम नाम निर्दिष्ट करने के लिए। |
| animation-duration | एनिमेशन की समय अवधि (सेकंड या मिलीसेकंड में) पूरा होने के लिए निर्दिष्ट करने के लिए। |
| animation-timing-function | एनिमेशन स्पीड कर्व निर्दिष्ट करने के लिए। |
| animation-delay | एनिमेशन शुरू होने से पहले कुछ देरी निर्दिष्ट करने के लिए। |
| animation-iteration-count | निर्दिष्ट करने के लिए कि एनिमेशन कितनी बार खेला जाना चाहिए। |
| animation-direction | यह इंगित करने के लिए कि एनिमेशन को वैकल्पिक या रिवर्स चक्र में चलना चाहिए या नहीं। |
| animation-fill-mode | उन मानों को निर्दिष्ट करने के लिए जो एनिमेशन द्वारा उस समय के बाहर लागू किए जाते हैं जब यह निष्पादित हो रहा होता है। |
| animation-play-state | यह निर्दिष्ट करने के लिए कि एनिमेशन वर्तमान में रुका हुआ है या चल रहा है। |
| initial | इस प्रॉपर्टी को उसके प्रारंभिक मान पर सेट करने के लिए। |
| inherit | पैरेंट प्रॉपर्टी मान को विरासत में लेने के लिए। |
उदाहरण
animation प्रॉपर्टी का उदाहरण देखते हैं:
<!DOCTYPE html> <html> <head> <style> div { width: 5px; height: 15px; background-color: limegreen; animation: demo 4s infinite; } @keyframes demo { from {width: 5px; background-color: limegreen;} to {width: 400px; background-color: darkgreen;} } @keyframes demo1 { from {height: 5px; background-color: limegreen;} to {height: 400px; background-color: darkgreen;} } </style> <script> function changeAnimation() { document.getElementById("DIV1").style.animation = "demo1 4s 2"; } </script> </head> <body> <button onclick="changeAnimation()">CHANGE ANIMATION</button> <p>Change the below animation by clicking the above button</p> <div id="DIV1"></div> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा:

CHANGE ANIMATION बटन पर क्लिक करने पर, एनिमेशन बदल जाएगा:
