SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS क्या है — शुरुआत से CSS सीखें (Hindi Tutorial) 2. CSS Syntax क्या है — Selector, Property, Value समझें 3. CSS Selectors — Class, ID, Attribute Selector Hindi में 4. HTML में CSS कैसे जोड़ें — Inline, Internal, External 5. CSS में रंग — HEX, RGB, RGBA, HSL Colour Guide 6. CSS Background — Image, Size, Position, Repeat सीखें 7. CSS Border — Style, Width, गोल कोने और Shadow 8. CSS Margin क्या है — Shorthand, Auto और Collapse 9. CSS Padding क्या है — Margin से अंतर समझें 10. CSS Height और Width — px, %, em, rem, vw, vh Units 11. CSS Box Model क्या है — Content, Padding, Border 12. CSS Text Styling — Color, Alignment और Spacing 13. CSS Fonts — font-family, Size और Google Fonts 14. CSS में Link Styling — Hover, Visited, Button बनाएँ 15. CSS में List Styling — Marker, Counter और Shorthand 16. CSS Table Styling — Zebra Stripe और Hover Row 17. CSS Display Property — Block, Inline, None समझें 18. CSS Position — Relative, Absolute, Fixed, Sticky समझें 19. CSS Overflow क्या है — Hidden, Scroll, Auto समझें 20. CSS Float और Clear — Layout और Clearfix Trick 21. CSS Pseudo-class — Hover, Focus, nth-child सीखें 22. CSS Pseudo-element — ::before, ::after, ::first-line सीखें 23. CSS Form Styling — Input, Label, Button सजाएँ 24. CSS Navigation Bar बनाएँ — Dropdown Menu के साथ 25. CSS Website Layout — Header, Sidebar, Footer बनाएँ 26. CSS Flexbox क्या है — Complete Guide Hindi में 27. CSS Grid क्या है — Columns, Rows, Layout Guide 28. CSS Responsive Design — Media Query हिंदी Tutorial 29. CSS Transitions और Animations — बिना JavaScript 30. CSS Variables क्या है — :root, var() और Theming 31. CSS Transform — Rotate, Scale, Translate सीखें 32. CSS Filter — Blur, Grayscale, Sepia Photo Effect सीखें 33. CSS Text Effects — Shadow, Wrapping, Overflow सीखें 34. CSS Keyframes — Bouncing Ball Animation बनाएँ 35. CSS Grid Template Areas — शब्दों में Layout बनाएँ
अंतिम टेस्ट — सर्टिफिकेट ₹10
इस कोड को लाइव चलाएँ
पाठ 34, कुल 35 में

CSS Keyframes — Bouncing Ball Animation बनाएँ

4 मिनट पढ़ें · मुफ़्त · बिना लॉगिन

भाषा:

flipbook सोचिए: आप page के नीचे एक गेंद बनाते हैं, फिर थोड़ी ऊपर, फिर सबसे ऊपर — और जब pages को तेज़ी से पलटते हैं, गेंद उछलने लगती है। आपने बीच की हर position नहीं बनाई; आपकी आँखों ने उन्हें भर दिया। CSS keyframes बिल्कुल ऐसे ही काम करते हैं। आप ज़रूरी पल बताते हैं — शुरुआत, बीच, अंत — और browser बीच का सब कुछ खुद, आराम से, बना देता है।

Diagram — देखें, यह सब कैसे जुड़ता है
Diagram: CSS कीफ़्रेम

कीफ़्रेम और animation की properties

animation के दो हिस्से हैं। पहला, @keyframes rule, जो animation का नाम देता है और उसके stops गिनाता है। दूसरा, element पर animation properties, जो बताती हैं कौनसे keyframes चलाने हैं और कैसे: animation-name, animation-duration (एक run कितनी देर चलेगा), animation-timing-function (speed का curve), animation-delay (शुरू होने से पहले इंतज़ार), animation-iteration-count (कितनी बार — या infinite), animation-direction, और animation-fill-mode।

@keyframes bounce {
  0%   { top: 0; }
  50%  { top: 180px; }
  100% { top: 0; }
}
.ball { animation: bounce 2s ease-in-out infinite; }

shorthand animation: bounce 2s ease-in-out infinite; नाम, duration, timing function और iteration count को एक line में समेट देता है — वही order, जैसे लंबी properties का है।

from और to, या percentages

सादे animations from और to इस्तेमाल करते हैं — बस शुरुआत और अंत, जैसे लगभग अदृश्य से पूरा दिखने तक fade होना। जब बीच में stops चाहिए, percentages इस्तेमाल कीजिए: 0% शुरुआत है, 100% अंत है, और 50% आधा रास्ता है। ऊपर वाली उछलती गेंद तीन stops इस्तेमाल करती है: ऊपर, नीचे, ऊपर। Percentages से एक property दूसरी से अलग वक़्त पर भी बदल सकती है — रंग 25% पर बदल सकता है जबकि position 50% पर बदलती है।

animation बनाम transition

transition को trigger चाहिए — आम तौर पर hover — और वह दो states के बीच चलती है। animation को किसी trigger की ज़रूरत नहीं: page load होते ही खुद चलती है, उसके कई stops हो सकते हैं, और वह हमेशा दोहराती रह सकती है। इसलिए animations उन चीज़ों के लिए सही हैं जो खुद हिलनी चाहिए — उछलती गेंद, धड़कता notification dot, loading spinner — जबकि transitions hover effects के लिए सही रहती हैं।

Note: जब animation ख़त्म होती है, element वापस अपनी आम style पर कूद जाता है, जब तक आप animation-fill-mode: forwards; न लगाएँ, जो आख़िरी keyframe की values को बनाए रखता है। इसके बिना, बाईं ओर से slide करके आया box animation ख़त्म होते ही वापस बाईं ओर कूद जाएगा।
Tip: आगे-पीछे आराम से हिलने के लिए, infinite count के साथ animation-direction: alternate; इस्तेमाल कीजिए। animation आगे चलती है, फिर पीछे, फिर आगे — इसलिए fade होता box पूरा दिखने से एकदम अदृश्य पर कभी नहीं कूदता।

आम गलतियाँ

  • animation-duration भूलना — बिना duration के animation 0 second की होती है और कुछ होता हुआ दिखाई नहीं देता।
  • keyframes का नाम animation-name से अलग लिखना — नाम बिल्कुल एक जैसे होने चाहिए, वरना browser को चलाने के लिए कोई animation नहीं मिलता।
  • top या left को ऐसे element पर animate करना जो positioned नहीं है — वह properties सिर्फ़ position: relative, absolute, या fixed वाले elements को हिलाती हैं।
  • यह उम्मीद करना कि element आख़िरी keyframe पर रुका रहेगा — बिना animation-fill-mode: forwards; के वह वापस अपनी आम style पर कूद जाता है।
  • animation: infinite; अकेला लिखना — shorthand को कम से कम नाम और duration चाहिए; सिर्फ़ iteration count काफ़ी नहीं।

याद रखें

  • @keyframes ज़रूरी stops गिनाता है; browser बीच का सब कुछ खुद बना देता है।
  • from/to दो stops हैं; percentages जितने चाहिए उतने stops देते हैं।
  • animation: नाम duration timing-function iteration-count; shorthand का order है।
  • animations खुद चलती हैं; transitions को hover जैसे trigger की ज़रूरत होती है।
  • animation-fill-mode: forwards; animation ख़त्म होने के बाद आख़िरी keyframe को बनाए रखता है।

उदाहरण समझिए

  • @keyframes bounce { 0% { top: 0; } 50% { top: 180px; } 100% { top: 0; } } — गेंद शुरुआत में ऊपर है, आधे रास्ते नीचे जाती है, और अंत में वापस ऊपर आ जाती है।
  • .ball { animation: bounce 2s ease-in-out infinite; } — उछाल 2 second चलती है, आराम से शुरू और ख़त्म होती है, और हमेशा दोहराती है।
  • @keyframes fadein { from { opacity: 0.2; } to { opacity: 1; } } — हरा box लगभग अदृश्य से पूरा दिखने तक fade होता है, सिर्फ़ दो stops से।
  • .fade-box { animation: fadein 3s ease-in-out infinite alternate; } — fade 3 second चलता है और आगे फिर पीछे खेलता है, इसलिए कभी एकदम नहीं कूदता।
  • .ball { position: absolute; } — गेंद सफ़ेद stage के अंदर positioned है, इसलिए top animate करने पर वह हिलती भी है।

उदाहरण

Example
<!DOCTYPE html>
<html>
<head>
<title>Bouncing Ball and Fading Box</title>
<style>
* { box-sizing: border-box; }
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f2f2f2; text-align: center; }
h1 { color: #333; }
.stage { max-width: 600px; height: 260px; margin: 20px auto; background-color: white; border-radius: 10px; position: relative; }
.ball {
  width: 60px; height: 60px; background-color: #e91e63; border-radius: 50%;
  position: absolute; left: 50px; top: 0;
  animation: bounce 2s ease-in-out infinite;
}
@keyframes bounce {
  0% { top: 0; }
  50% { top: 180px; }
  100% { top: 0; }
}
.fade-box {
  width: 200px; height: 120px; margin: 30px auto; background-color: #04aa6d;
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: bold; border-radius: 10px;
  animation: fadein 3s ease-in-out infinite alternate;
}
@keyframes fadein {
  from { opacity: 0.2; }
  to { opacity: 1; }
}
p.note { color: #666; max-width: 600px; margin: 20px auto; }
</style>
</head>
<body>

<h1>Motion Without JavaScript</h1>

<div class="stage">
<div class="ball"></div>
</div>

<div class="fade-box">I fade in and out</div>

<p class="note">In a browser, the pink ball bounces up and down forever and the green box fades in and out. The static picture here shows the starting pose — the motion lives in the @keyframes rules.</p>

</body>
</html>

परिणाम

परिणाम — ब्राउज़र में यह कैसा दिखता है
परिणाम: CSS Keyframes — Bouncing Ball Animation बनाएँ

खुद करके देखें — लाइव एडिटर

नीचे दिया गया कोड बदलें और चलाएँ दबाएँ — परिणाम तुरंत दिखेगा। कोई फाइल सहेजनी नहीं है, कोई लॉगिन नहीं चाहिए।

परिणाम

अक्सर पूछे जाने वाले सवाल

इस पाठ के बारे में सबसे ज़्यादा पूछे जाने वाले सवाल — सवाल पढ़ें, फिर खोलकर जवाब देखें।

1. Keyframes रूल क्या होता है?

एक रूल जो animation को नाम देता है और उसके ज़रूरी stops बताता है। बीच का सब कुछ ब्राउज़र अपने आप smoothly बना देता है।

2. From/to और percentages में क्या फ़र्क है?

From/to सिर्फ़ दो stops देता है, शुरुआत और अंत। Percentages जितने चाहिए उतने stops देते हैं, जैसे 0%, 50% और 100%।

3. Animation को duration क्यों चाहिए?

बिना duration के यह 0 seconds पर डिफ़ॉल्ट हो जाता है, तो कुछ होता हुआ दिखता ही नहीं।

खुद क्यों सीखें — AI से पूछने के बजाय?

AI आपके लिए कोड लिख सकता है, लेकिन वह आपके लिए सोच नहीं सकता। जब आप HTML खुद सीखते हैं, तो आपका दिमाग असली कौशल बनाता है: आप समझते हैं कि पेज ऐसा क्यों दिखता है, टूटने पर उसे ठीक कर सकते हैं, और परीक्षा या इंटरव्यू में बिना मदद के जवाब दे सकते हैं। यही कौशल नौकरी दिलाता है — कॉपी किया हुआ जवाब नहीं।

सर्टिफिकेट पाएँ — सिर्फ ₹10

सभी 35 पाठ पूरे करें, टेस्ट पास करें (80%), ₹10 दें और अपना सर्टिफिकेट पाएँ।

टेस्ट दें

देखकर सीखना पसंद है? वीडियो कोर्स में वही विषय एक-एक करके सिखाए जाते हैं।

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Ethical Hacking & Cyber Security Workshop
View
Advanced Cyber Security Industrial Training
₹5,000
View
Core Python Programming – 3 Month Complete Course
₹700
View
Browse all courses
CSS — Lessons
1. CSS क्या है — शुरुआत से CSS सीखें (Hindi Tutorial) 2. CSS Syntax क्या है — Selector, Property, Value समझें 3. CSS Selectors — Class, ID, Attribute Selector Hindi में 4. HTML में CSS कैसे जोड़ें — Inline, Internal, External 5. CSS में रंग — HEX, RGB, RGBA, HSL Colour Guide 6. CSS Background — Image, Size, Position, Repeat सीखें 7. CSS Border — Style, Width, गोल कोने और Shadow 8. CSS Margin क्या है — Shorthand, Auto और Collapse 9. CSS Padding क्या है — Margin से अंतर समझें 10. CSS Height और Width — px, %, em, rem, vw, vh Units 11. CSS Box Model क्या है — Content, Padding, Border 12. CSS Text Styling — Color, Alignment और Spacing 13. CSS Fonts — font-family, Size और Google Fonts 14. CSS में Link Styling — Hover, Visited, Button बनाएँ 15. CSS में List Styling — Marker, Counter और Shorthand 16. CSS Table Styling — Zebra Stripe और Hover Row 17. CSS Display Property — Block, Inline, None समझें 18. CSS Position — Relative, Absolute, Fixed, Sticky समझें 19. CSS Overflow क्या है — Hidden, Scroll, Auto समझें 20. CSS Float और Clear — Layout और Clearfix Trick 21. CSS Pseudo-class — Hover, Focus, nth-child सीखें 22. CSS Pseudo-element — ::before, ::after, ::first-line सीखें 23. CSS Form Styling — Input, Label, Button सजाएँ 24. CSS Navigation Bar बनाएँ — Dropdown Menu के साथ 25. CSS Website Layout — Header, Sidebar, Footer बनाएँ 26. CSS Flexbox क्या है — Complete Guide Hindi में 27. CSS Grid क्या है — Columns, Rows, Layout Guide 28. CSS Responsive Design — Media Query हिंदी Tutorial 29. CSS Transitions और Animations — बिना JavaScript 30. CSS Variables क्या है — :root, var() और Theming 31. CSS Transform — Rotate, Scale, Translate सीखें 32. CSS Filter — Blur, Grayscale, Sepia Photo Effect सीखें 33. CSS Text Effects — Shadow, Wrapping, Overflow सीखें 34. CSS Keyframes — Bouncing Ball Animation बनाएँ 35. CSS Grid Template Areas — शब्दों में Layout बनाएँ
अंतिम टेस्ट — सर्टिफिकेट ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🛡️ 7-Day Money-Back Guarantee
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Download karne ke liye login karo. Login ke baad yahi page pe rahoge!

Naya ho? Register karo →