Animation Component

Animation Component: UIKit provides a powerful animation system with various built-in animations that can be easily applied to elements.

Live Examples

1. Basic Animations

Example Preview - Click buttons to trigger animations

Animate Me!

2. Animation on Scroll

Example Preview - Scroll to see animations

Fade In

This card fades in when scrolled into view.

Slide Left

This card slides from the right.

Scale Up

This card scales up when visible.

Repeat Animation

This animation repeats every time it comes into view.

Ken Burns Effect

This uses the Ken Burns animation effect.

3. Animation with Duration & Delay

Example Preview
Fast

0.1s duration

Default

0.2s duration

Slow

0.5s duration

Reverse

Reverse direction

Staggered Animations

Delay: 100ms

Delay: 200ms

Delay: 300ms

4. Hover Animations

Example Preview - Hover over cards
Scale Up

Hover to scale up

Slide Top

Hover to slide up

Shake

Hover to shake

Animation Classes Reference

All Available Animations

Animation ClassDescriptionExample
.uk-animation-fadeFade in/out
Fade effect
.uk-animation-scale-upScale up from center
Scale up
.uk-animation-scale-downScale down to center
Scale down
.uk-animation-slide-topSlide from top
Slide top
.uk-animation-slide-bottomSlide from bottom
Slide bottom
.uk-animation-slide-leftSlide from left
Slide left
.uk-animation-slide-rightSlide from right
Slide right
.uk-animation-kenburnsKen Burns effect (zoom pan)
Ken Burns
.uk-animation-shakeShake horizontally
Shake
.uk-animation-strokeStroke animation for SVGs
Stroke

Modifier Classes

Modifier ClassDescriptionUsage
.uk-animation-fastFast animation (0.1s)uk-animation-fade uk-animation-fast
.uk-animation-slowSlow animation (0.5s)uk-animation-fade uk-animation-slow
.uk-animation-reverseReverse animation directionuk-animation-slide-top uk-animation-reverse
.uk-animation-hoverTrigger on hoveruk-animation-scale-up uk-animation-hover

JavaScript Methods

Animation Component:
// Get animation instance
                const animation = UIkit.animation(element, options);

                // Start animation
                animation.start();

                // Stop animation
                animation.stop();

                // Check if animating
                animation.isAnimating();
Scrollspy Component:
// Get scrollspy instance
                const scrollspy = UIkit.scrollspy(element, options);

                // Update scrollspy
                scrollspy.update();

                // Get currently active elements
                scrollspy.getActive();

                // Example: Trigger animation programmatically
                const element = document.getElementById('myElement');
                UIkit.animation(element, {
                name: 'slide-top',
                duration: 500
                }).start();

Complete Example

<!DOCTYPE html>
                <html lang="en">
                <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>UIKit Animations Demo</title>
                <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.19.2/dist/css/uikit.min.css" />
                <style>
                    body { padding: 20px; }
                    .demo-section { margin-bottom: 50px; }
                    .animated-box {
                        width: 100px;
                        height: 100px;
                        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                        margin: 10px;
                        display: inline-flex;
                        align-items: center;
                        justify-content: center;
                        color: white;
                        border-radius: 10px;
                    }
                </style>
                </head>
                <body>
                <div class="uk-container">
                    <h1>UIKit Animations Demo</h1>
                    
                    <!-- Animation Controls -->
                    <div class="demo-section">
                        <h3>Interactive Animations</h3>
                        <div class="uk-margin">
                            <button class="uk-button uk-button-primary" onclick="triggerFade()">Fade Animation</button>
                            <button class="uk-button uk-button-secondary" onclick="triggerSlide()">Slide Animation</button>
                            <button class="uk-button uk-button-danger" onclick="triggerScale()">Scale Animation</button>
                            <button class="uk-button uk-button-default" onclick="resetAnimations()">Reset All</button>
                        </div>
                        
                        <div id="demoBox" class="animated-box">
                            Animation Box
                        </div>
                    </div>
                    
                    <!-- Scroll Animations -->
                    <div class="demo-section">
                        <h3>Scroll Triggered Animations</h3>
                        <div class="uk-grid-small uk-child-width-1-3@m" uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card; delay: 200">
                            <div>
                                <div class="uk-card uk-card-primary uk-card-body">
                                    <h4 class="uk-card-title">Card 1</h4>
                                    <p>Fades in on scroll</p>
                                </div>
                            </div>
                            <div>
                                <div class="uk-card uk-card-secondary uk-card-body" uk-scrollspy="cls: uk-animation-slide-left; delay: 300">
                                    <h4 class="uk-card-title">Card 2</h4>
                                    <p>Slides from left</p>
                                </div>
                            </div>
                            <div>
                                <div class="uk-card uk-card-default uk-card-body" uk-scrollspy="cls: uk-animation-scale-up; delay: 400">
                                    <h4 class="uk-card-title">Card 3</h4>
                                    <p>Scales up</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Hover Animations -->
                    <div class="demo-section">
                        <h3>Hover Effects</h3>
                        <div class="uk-grid-small uk-child-width-1-4@m" uk-grid>
                            <div>
                                <div class="uk-card uk-card-default uk-card-body uk-animation-hover uk-animation-scale-up">
                                    <h5>Scale Up</h5>
                                    <p>Hover me!</p>
                                </div>
                            </div>
                            <div>
                                <div class="uk-card uk-card-default uk-card-body uk-animation-hover uk-animation-slide-top">
                                    <h5>Slide Up</h5>
                                    <p>Hover me!</p>
                                </div>
                            </div>
                            <div>
                                <div class="uk-card uk-card-default uk-card-body uk-animation-hover uk-animation-shake">
                                    <h5>Shake</h5>
                                    <p>Hover me!</p>
                                </div>
                            </div>
                            <div>
                                <div class="uk-card uk-card-default uk-card-body uk-animation-hover uk-animation-slide-left">
                                    <h5>Slide Left</h5>
                                    <p>Hover me!</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- UIKit JS -->
                <script src="https://cdn.jsdelivr.net/npm/uikit@3.19.2/dist/js/uikit.min.js"></script>
                <script src="https://cdn.jsdelivr.net/npm/uikit@3.19.2/dist/js/uikit-icons.min.js"></script>

                <script>
                    // Animation Functions
                    function triggerFade() {
                        const box = document.getElementById('demoBox');
                        resetBox(box);
                        box.classList.add('uk-animation-fade', 'uk-animation-fast');
                        setTimeout(() => box.classList.remove('uk-animation-fade'), 1000);
                    }
                    
                    function triggerSlide() {
                        const box = document.getElementById('demoBox');
                        resetBox(box);
                        box.classList.add('uk-animation-slide-bottom', 'uk-animation-slow');
                        setTimeout(() => box.classList.remove('uk-animation-slide-bottom'), 1000);
                    }
                    
                    function triggerScale() {
                        const box = document.getElementById('demoBox');
                        resetBox(box);
                        box.classList.add('uk-animation-scale-up', 'uk-animation-reverse');
                        setTimeout(() => box.classList.remove('uk-animation-scale-up'), 1000);
                    }
                    
                    function resetAnimations() {
                        const box = document.getElementById('demoBox');
                        resetBox(box);
                    }
                    
                    function resetBox(box) {
                        // Remove all animation classes
                        const classes = box.className.split(' ');
                        const newClasses = classes.filter(cls => !cls.startsWith('uk-animation-'));
                        box.className = newClasses.join(' ');
                    }
                    
                    // Programmatic animation example
                    setTimeout(() => {
                        const box = document.getElementById('demoBox');
                        UIkit.animation(box, {
                            name: 'slide-right',
                            duration: 1000
                        }).start();
                    }, 2000);
                </script>
                </body>
                </html>

Animation Options

OptionTypeDefaultDescription
nameString'fade'Animation name (fade, slide-top, etc.)
durationNumber200Animation duration in ms
timingString'ease'Animation timing function
delayNumber0Delay before animation starts
reverseBooleanfalsePlay animation in reverse
infiniteBooleanfalseRepeat animation infinitely

Scrollspy Options

OptionTypeDefaultDescription
clsString'uk-active'Class to add when in view
hiddenBooleantrueHide elements initially
offsetTopNumber0Top offset before triggering
offsetLeftNumber0Left offset before triggering
repeatBooleanfalseRepeat animation on every view
delayNumber0Delay before animation starts
Best Practices:
  • Use subtle animations for better user experience
  • Keep animation durations short (200-500ms)
  • Use consistent animation patterns throughout your site
  • Consider performance - avoid animating too many elements at once
  • Test animations on different devices and browsers
  • Provide animation controls for users with motion sensitivity
  • Use scroll animations sparingly - too many can be distracting

Custom Animation Example

/* Custom Animation CSS */
                @keyframes custom-bounce {
                0%, 100% { transform: translateY(0); }
                50% { transform: translateY(-20px); }
                }

                @keyframes custom-spin {
                from { transform: rotate(0deg); }
                to { transform: rotate(360deg); }
                }

                @keyframes custom-gradient {
                0% { background-position: 0% 50%; }
                50% { background-position: 100% 50%; }
                100% { background-position: 0% 50%; }
                }

                /* UIKit compatible custom animation classes */
                .uk-animation-custom-bounce {
                animation: custom-bounce 0.5s ease infinite;
                }

                .uk-animation-custom-spin {
                animation: custom-spin 2s linear infinite;
                }

                .uk-animation-custom-gradient {
                background: linear-gradient(135deg, #667eea, #764ba2, #f093fb, #f5576c);
                background-size: 400% 400%;
                animation: custom-gradient 3s ease infinite;
                }

                /* Usage in HTML */
                <div class="uk-card uk-animation-custom-bounce">
                Bouncing Card
                </div>

                <div class="uk-card uk-animation-custom-spin">
                Spinning Icon
                </div>

                <div class="uk-card uk-animation-custom-gradient">
                Gradient Background
                </div>