{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "transitions-animations", "title": "Animations", "description": "Bring interactivity to your UI by smoothly transitioning properties and creating keyframe-driven animations.", "difficulty": "beginner", "lessons": [ { "id": "transitions-1", "title": "Transitions", "description": "Learn how to apply transition to properties for smooth changes on state changes.", "task": "Add transition: background-color 0.3s to .btn so the color fades smoothly on hover.", "previewHTML": "", "previewBaseCSS": "body { font-family: sans-serif; padding: 1rem; } .btn { background: black; color: white; padding: 0.5rem 1rem; border: none; cursor: pointer; } .btn:hover { background: white; color: black; }", "sandboxCSS": "", "codePrefix": "/* Add transition */\n.btn {", "initialCode": "", "codeSuffix": "}", "solution": " transition: background-color 0.3s;", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "transition", "message": "Use the transition property", "options": { "caseSensitive": false } }, { "type": "regex", "value": "transition:\\s*background-color\\s*0\\.3s", "message": "Set transition: background-color 0.3s", "options": { "caseSensitive": false } } ] }, { "id": "transitions-2", "title": "Timing Funcs", "description": "Explore easing functions like ease, linear, ease-in, ease-out to control animation pacing.", "task": "Set transition-timing-function to ease-in-out on .btn.", "previewHTML": "", "previewBaseCSS": "body { font-family: sans-serif; padding: 1rem; } .btn { background: navy; color: gold; padding: 0.5rem 1rem; border: none; cursor: pointer; transition: all 0.5s; } .btn:hover { background: gold; color: navy; transform: scale(1.1); }", "sandboxCSS": "", "codePrefix": "/* Set timing function */\n.btn {", "initialCode": "", "codeSuffix": "}", "solution": " transition-timing-function: ease-in-out;", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "transition-timing-function", "message": "Use transition-timing-function", "options": { "caseSensitive": false } }, { "type": "property_value", "value": { "property": "transition-timing-function", "expected": "ease-in-out" }, "message": "Set timing to ease-in-out" } ] }, { "id": "transitions-3", "title": "Keyframes", "description": "Create named animations using @keyframes and apply them via the animation shorthand.", "task": "Define a keyframe at 50% with transform: translateY(-20px) and apply animation: bounce 1s infinite to .ball.", "previewHTML": "
", "previewBaseCSS": "body { font-family: sans-serif; padding: 1rem; } .ball { width: 50px; height: 50px; background: crimson; border-radius: 50%; margin: 2rem auto; }", "sandboxCSS": "", "codePrefix": "/* Define keyframes and apply animation */\n@keyframes bounce {", "initialCode": "", "codeSuffix": "}\n.ball { }", "solution": " 50% { transform: translateY(-20px); }\n}\n.ball {\n animation: bounce 1s infinite;", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "@keyframes bounce", "message": "Define @keyframes bounce", "options": { "caseSensitive": false } }, { "type": "regex", "value": "50%.*transform: translateY\\(-20px\\)", "message": "At 50%, use transform: translateY(-20px)", "options": { "caseSensitive": false } }, { "type": "contains", "value": "animation", "message": "Use animation property on .ball", "options": { "caseSensitive": false } }, { "type": "regex", "value": "animation:.*bounce.*1s.*infinite", "message": "Apply animation: bounce 1s infinite", "options": { "caseSensitive": false } } ] }, { "id": "transitions-4", "title": "Anim Properties", "description": "Fine-tune animations with animation-delay, animation-iteration-count, animation-direction, and animation-fill-mode.", "task": "Apply the pulse animation to .box with animation-name: pulse, animation-duration: 2s, animation-delay: 1s, animation-iteration-count: 2, and animation-fill-mode: forwards.", "previewHTML": "