/*!
* Sherlock Animation Library
* A lightweight, vanilla CSS animation library powered by CSS custom properties (variables) for easy theme control.
*
* Features:
* - 18+ reusable animations (entrances, effects, infinite loops).
* - Fully customizable via CSS variables (colors, durations, easing, scales, etc.).
* - Hardware-accelerated with translate3d() for smooth performance.
* - Responsive and themeable (light/dark modes, custom brands).
* - No JavaScript required. Just add a class to any element!
*
* Quick Start:
* 1. Copy-paste this into your CSS (or <style> tag).
* 2. Customize :root variables for your theme.
* 3. Add classes like `.animate-fade-in` to elements.
* 4. Override per-element: `<div class="animate-fade-in" style="--animate-duration: 1s;">...</div>`
*
* Modifiers:
* - `.animate-reverse` : Reverses animation direction (great for exits).
* - `.animate-paused` : Pauses animation (animation-play-state: paused).
* - `.animate-fill-forwards` : Ensures end state persists (animation-fill-mode: forwards; default for entrances).
*
* Global Controls (edit :root):
* - Durations, easing, colors, scales, etc.
*
* Infinite Animations: Automatically loop (e.g., `.animate-pulse`, `.animate-spin`).
*
* Built by Sherlock (Trailblazer Labs) • MIT License
*/
/* ==========================================================================
ROOT VARIABLES (Theme & Animation Controls)
========================================================================== */
:root {
/* Theme Colors */
--color-primary: #007bff;
--color-secondary: #6c757d;
--color-success: #28a745;
--color-danger: #dc3545;
--color-warning: #ffc107;
--color-info: #17a2b8;
--color-light: #f8f9fa;
--color-dark: #343a40;
--color-background: #ffffff;
--color-text: #212529;
/* Animation Base */
--animate-duration: 0.6s;
--animate-duration-fast: 0.3s;
--animate-duration-slow: 1s;
--animate-delay: 0s;
--animate-easing: cubic-bezier(0.25, 0.46, 0.45, 0.94); /* easeOutQuart */
--animate-timing: var(--animate-easing);
/* Transform & Effects */
--animate-scale: 1.05;
--animate-scale-large: 1.2;
--animate-rotate: 360deg;
--animate-translate-y: 30px;
--animate-translate-x: 30px;
--animate-opacity: 0;
--animate-glow-color: var(--color-primary);
--animate-glow-intensity: 0 0 20px var(--color-primary);
--animate-glow-spread: 0 0 5px 10px rgba(0, 123, 255, 0.5);
}
/* Dark mode example (override in your media query) */
@media (prefers-color-scheme: dark) {
:root {
--color-background: #121212;
--color-text: #e0e0e0;
--color-primary: #4dabf7;
--animate-glow-color: var(--color-primary);
}
}
/* Animation Base Classes (Modifiers) */
.animate-reverse {
animation-direction: reverse !important;
}
.animate-paused {
animation-play-state: paused !important;
}
.animate-fill-forwards {
animation-fill-mode: forwards !important;
}
/* Per-element overrides via inline styles work great with vars! */
/* ==========================================================================
KEYFRAMES
========================================================================== */
/* Fade */
@keyframes fadeIn {
from { opacity: var(--animate-opacity); }
to { opacity: 1; }
}
/* Slide/Fade Entrances */
@keyframes fadeInUp {
from {
opacity: var(--animate-opacity);
transform: translate3d(0, var(--animate-translate-y), 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
}
}
@keyframes fadeInDown {
from {
opacity: var(--animate-opacity);
transform: translate3d(0, calc(-1 * var(--animate-translate-y)), 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
}
}
@keyframes fadeInLeft {
from {
opacity: var(--animate-opacity);
transform: translate3d(calc(-1 * var(--animate-translate-x)), 0, 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
}
}
@keyframes fadeInRight {
from {
opacity: var(--animate-opacity);
transform: translate3d(var(--animate-translate-x), 0, 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
}
}
/* Scale Entrances */
@keyframes zoomIn {
from {
opacity: var(--animate-opacity);
transform: scale3d(0.3, 0.3, 0.3);
}
to {
opacity: 1;
transform: scale3d(1, 1, 1);
}
}
@keyframes bounceIn {
0%, 20%, 40%, 60%, 80% {
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
}
0% { opacity: 0; transform: scale3d(0.3, 0.3, 0.3); }
20% { transform: scale3d(1.1, 1.1, 1.1); }
40% { transform: scale3d(0.9, 0.9, 0.9); }
60% { opacity: 1; transform: scale3d(1.03, 1.03, 1.03); }
80% { transform: scale3d(0.97, 0.97, 0.97); }
100% { opacity: 1; transform: scale3d(1, 1, 1); }
}
/* Effects */
@keyframes pulse {
0% { transform: scale3d(1, 1, 1); }
50% { transform: scale3d(var(--animate-scale), var(--animate-scale), var(--animate-scale)); }
100% { transform: scale3d(1, 1, 1); }
}
@keyframes heartbeat {
0% { transform: scale3d(1, 1, 1); }
14% { transform: scale3d(1.3, 0.9, 1); }
28% { transform: scale3d(1, 1.2, 1); }
42% { transform: scale3d(1.3, 1, 1); }
70% { transform: scale3d(1, 1.1, 1); }
100% { transform: scale3d(1, 1, 1); }
}
@keyframes shakeX {
0%, 100% { transform: translate3d(0, 0, 0); }
10%, 30%, 50%, 70%, 90% { transform: translate3d(-10px, 0, 0); }
20%, 40%, 60%, 80% { transform: translate3d(10px, 0, 0); }
}
@keyframes shakeY {
0%, 100% { transform: translate3d(0, 0, 0); }
10%, 30%, 50%, 70%, 90% { transform: translate3d(0, -10px, 0); }
20%, 40%, 60%, 80% { transform: translate3d(0, 10px, 0); }
}
@keyframes spin {
from { transform: rotate3d(0, 0, 1, 0deg); }
to { transform: rotate3d(0, 0, 1, var(--animate-rotate)); }
}
@keyframes glow {
0%, 100% { box-shadow: var(--animate-glow-intensity); }
50% { box-shadow: var(--animate-glow-spread); }
}
@keyframes rubberBand {
0% { transform: scale3d(1, 1, 1); }
30% { transform: scale3d(1.25, 0.75, 1); }
40% { transform: scale3d(0.75, 1.25, 1); }
50% { transform: scale3d(1.15, 0.85, 1); }
65% { transform: scale3d(0.95, 1.05, 1); }
75% { transform: scale3d(1.05, 0.95, 1); }
100% { transform: scale3d(1, 1, 1); }
}
@keyframes tada {
0% { transform: scale3d(1, 1, 1); }
10%, 20% { transform: scale3d(0.9, 0.9, 0.9) rotate3d(0, 0, 1, -3deg); }
30%, 50%, 70%, 90% { transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg); }
40%, 60%, 80% { transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg); }
100% { transform: scale3d(1, 1, 1); }
}
/* Flip */
@keyframes flipInX {
from {
opacity: var(--animate-opacity);
transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
}
to {
opacity: 1;
transform: perspective(400px) rotate3d(1, 0, 0, 0deg);
}
}
/* ==========================================================================
ANIMATION CLASSES
Apply to any element: <div class="animate-fade-in">...</div>
========================================================================== */
/* Entrances (play once, fill forwards) */
.animate-fade-in {
animation: fadeIn var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-fade-in-up {
animation: fadeInUp var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-fade-in-down {
animation: fadeInDown var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-fade-in-left {
animation: fadeInLeft var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-fade-in-right {
animation: fadeInRight var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-zoom-in {
animation: zoomIn var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-bounce-in {
animation: bounceIn var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-rubber-band {
animation: rubberBand var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-tada {
animation: tada var(--animate-duration) var(--animate-timing) var(--animate-delay) forwards;
}
.animate-flip-in-x {
animation: flipInX var(--animate-duration-fast) var(--animate-timing) var(--animate-delay) forwards;
}
/* Infinite Effects */
.animate-pulse {
animation: pulse var(--animate-duration-slow) infinite var(--animate-timing);
}
.animate-heartbeat {
animation: heartbeat 1.3s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}
.animate-shake-x {
animation: shakeX var(--animate-duration) infinite var(--animate-timing);
}
.animate-shake-y {
animation: shakeY var(--animate-duration) infinite var(--animate-timing);
}
.animate-spin {
animation: spin var(--animate-duration-slow) infinite linear;
}
.animate-glow {
animation: glow var(--animate-duration-slow) infinite var(--animate-timing);
box-shadow: var(--animate-glow-intensity);
}
/* Performance boost for animated elements */
@supports (will-change: transform) {
[class*="animate-"]:not(.animate-paused) {
will-change: transform, opacity;
}
}
Usage Examples
<!DOCTYPE html>
<html>
<head>
<!-- Paste the CSS above here -->
</head>
<body>
<!-- Entrance on load -->
<h1 class="animate-fade-in-up">Welcome!</h1>
<!-- Infinite spinner -->
<div class="animate-spin" style="--animate-duration: 2s;">🔄</div>
<!-- Pulsing button with custom theme -->
<button class="animate-pulse" style="--animate-duration: 1.5s; --animate-scale: 1.15;">Pulse Me</button>
<!-- Exit effect -->
<div class="animate-fade-in-left animate-reverse">Slide Out</div>
<!-- Glow with theme color -->
<div class="animate-glow" style="--animate-glow-color: #ff6b6b;">Glow Effect</div>
</body>
</html>
Customization Tips
- Global Theme: Edit
:root vars (e.g., --color-primary: #your-brand-color;).
- Per-Animation: Use inline styles like
style="--animate-duration: 0.8s; --animate-scale: 1.3;".
- Dark Mode: Override vars in
@media (prefers-color-scheme: dark).
- Easing Presets: Swap
--animate-easing (e.g., ease, cubic-bezier(0.68, -0.55, 0.265, 1.55) for bounce).
- Extend: Add new
@keyframes and classes easily.
This library is production-ready, performant, and infinitely customizable. No dependencies! 🚀