|
@@ -0,0 +1,339 @@
|
|
|
|
|
+<!DOCTYPE html>
|
|
|
|
|
+<html lang="en">
|
|
|
|
|
+<head>
|
|
|
|
|
+ <meta charset="UTF-8">
|
|
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
+ <title>CSS Selector - Anime.js</title>
|
|
|
|
|
+ <style>
|
|
|
|
|
+ :root {
|
|
|
|
|
+ --bg-color: #111;
|
|
|
|
|
+ --text-color: #9b9b9b;
|
|
|
|
|
+ --highlight-color: #ff4b4b;
|
|
|
|
|
+ --secondary-color: #2a2a2e;
|
|
|
|
|
+ --accent-color: #ff9f43;
|
|
|
|
|
+ --code-bg: #000;
|
|
|
|
|
+ --orange: #FF8F42; /* Anime.js orange */
|
|
|
|
|
+ --border-color: #222;
|
|
|
|
|
+ }
|
|
|
|
|
+ body {
|
|
|
|
|
+ background-color: var(--bg-color);
|
|
|
|
|
+ color: var(--text-color);
|
|
|
|
|
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
|
|
|
|
+ margin: 0;
|
|
|
|
|
+ padding: 40px;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: center;
|
|
|
|
|
+ }
|
|
|
|
|
+ .container {
|
|
|
|
|
+ max-width: 900px;
|
|
|
|
|
+ width: 100%;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* Header Section */
|
|
|
|
|
+ h1 {
|
|
|
|
|
+ color: var(--orange);
|
|
|
|
|
+ font-size: 42px;
|
|
|
|
|
+ margin-bottom: 15px;
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ letter-spacing: -1px;
|
|
|
|
|
+ }
|
|
|
|
|
+ .description {
|
|
|
|
|
+ font-size: 18px;
|
|
|
|
|
+ line-height: 1.5;
|
|
|
|
|
+ margin-bottom: 40px;
|
|
|
|
|
+ color: #ccc;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ h2 {
|
|
|
|
|
+ font-size: 24px;
|
|
|
|
|
+ color: #fff;
|
|
|
|
|
+ margin-bottom: 10px;
|
|
|
|
|
+ font-weight: 500;
|
|
|
|
|
+ }
|
|
|
|
|
+ p {
|
|
|
|
|
+ margin-top: 0;
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+ line-height: 1.6;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ code.inline {
|
|
|
|
|
+ background: rgba(255,255,255,0.1);
|
|
|
|
|
+ color: #e6e6e6;
|
|
|
|
|
+ padding: 2px 6px;
|
|
|
|
|
+ border-radius: 3px;
|
|
|
|
|
+ font-family: 'Roboto Mono', monospace;
|
|
|
|
|
+ font-size: 0.9em;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* Code & Demo Box */
|
|
|
|
|
+ .box-container {
|
|
|
|
|
+ margin-top: 50px;
|
|
|
|
|
+ background: #171717; /* slightly lighter than bg */
|
|
|
|
|
+ border-radius: 6px;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .box-header {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: space-between;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ padding: 0 20px;
|
|
|
|
|
+ height: 50px;
|
|
|
|
|
+ background: rgba(255,255,255,0.02);
|
|
|
|
|
+ border-bottom: 1px solid var(--border-color);
|
|
|
|
|
+ }
|
|
|
|
|
+ .box-title {
|
|
|
|
|
+ color: var(--orange);
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ font-size: 14px;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .tabs {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ gap: 20px;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ }
|
|
|
|
|
+ .tab {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ height: 100%;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ color: #666;
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ font-size: 13px;
|
|
|
|
|
+ border-bottom: 2px solid transparent;
|
|
|
|
|
+ transition: color 0.2s;
|
|
|
|
|
+ }
|
|
|
|
|
+ .tab:hover {
|
|
|
|
|
+ color: #999;
|
|
|
|
|
+ }
|
|
|
|
|
+ .tab.active {
|
|
|
|
|
+ color: var(--orange);
|
|
|
|
|
+ border-bottom-color: var(--orange);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .code-view, .html-view {
|
|
|
|
|
+ background: var(--code-bg);
|
|
|
|
|
+ padding: 20px;
|
|
|
|
|
+ font-family: 'Roboto Mono', 'Monaco', monospace;
|
|
|
|
|
+ font-size: 13px;
|
|
|
|
|
+ line-height: 1.6;
|
|
|
|
|
+ color: #abb2bf;
|
|
|
|
|
+ overflow-x: auto;
|
|
|
|
|
+ display: none;
|
|
|
|
|
+ }
|
|
|
|
|
+ .code-view.active, .html-view.active {
|
|
|
|
|
+ display: block;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* Syntax Highlighting Mock */
|
|
|
|
|
+ .kwd { color: #c678dd; } /* keyword */
|
|
|
|
|
+ .str { color: #98c379; } /* string */
|
|
|
|
|
+ .fun { color: #61afef; } /* function */
|
|
|
|
|
+ .num { color: #d19a66; } /* number */
|
|
|
|
|
+ .tag { color: #e06c75; } /* tag */
|
|
|
|
|
+ .attr { color: #d19a66; } /* attribute */
|
|
|
|
|
+ .val { color: #98c379; } /* value */
|
|
|
|
|
+ .punc { color: #abb2bf; } /* punctuation */
|
|
|
|
|
+
|
|
|
|
|
+ /* Visual Demo */
|
|
|
|
|
+ .demo-visual {
|
|
|
|
|
+ padding: 30px;
|
|
|
|
|
+ background: #1a1a1a;
|
|
|
|
|
+ border-top: 1px solid var(--border-color);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .row {
|
|
|
|
|
+ position: relative;
|
|
|
|
|
+ padding: 20px 0;
|
|
|
|
|
+ border-bottom: 1px solid #2a2a2a;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ }
|
|
|
|
|
+ .row:last-child {
|
|
|
|
|
+ border-bottom: none;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .square {
|
|
|
|
|
+ width: 28px;
|
|
|
|
|
+ height: 28px;
|
|
|
|
|
+ background-color: var(--highlight-color);
|
|
|
|
|
+ border-radius: 2px;
|
|
|
|
|
+ }
|
|
|
|
|
+ #css-selector-id {
|
|
|
|
|
+ background-color: var(--accent-color);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .action-bar {
|
|
|
|
|
+ padding: 15px 30px;
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ justify-content: flex-end;
|
|
|
|
|
+ border-top: 1px solid var(--border-color);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ .play-btn {
|
|
|
|
|
+ background: transparent;
|
|
|
|
|
+ border: 1px solid #444;
|
|
|
|
|
+ color: #fff;
|
|
|
|
|
+ padding: 6px 14px;
|
|
|
|
|
+ border-radius: 100px;
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+ font-weight: 600;
|
|
|
|
|
+ cursor: pointer;
|
|
|
|
|
+ transition: all 0.2s;
|
|
|
|
|
+ }
|
|
|
|
|
+ .play-btn:hover {
|
|
|
|
|
+ border-color: var(--orange);
|
|
|
|
|
+ color: var(--orange);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ </style>
|
|
|
|
|
+</head>
|
|
|
|
|
+<body>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="container">
|
|
|
|
|
+ <!-- Breadcrumb / Header -->
|
|
|
|
|
+ <div style="font-size: 10px; font-weight: bold; letter-spacing: 1px; color: #ff4b4b; margin-bottom: 20px;">ANIMATION > TARGETS</div>
|
|
|
|
|
+
|
|
|
|
|
+ <h1>CSS Selector</h1>
|
|
|
|
|
+ <p class="description">Targets one or multiple DOM Elements using a CSS selector.</p>
|
|
|
|
|
+
|
|
|
|
|
+ <h2>Accepts</h2>
|
|
|
|
|
+ <p>Any <code class="inline">String</code> accepted by <code class="inline">document.querySelectorAll()</code></p>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="box-container">
|
|
|
|
|
+ <div class="box-header">
|
|
|
|
|
+ <div class="box-title">CSS Selector code example</div>
|
|
|
|
|
+ <div class="tabs">
|
|
|
|
|
+ <div class="tab active" onclick="switchTab('js')">JavaScript</div>
|
|
|
|
|
+ <div class="tab" onclick="switchTab('html')">HTML</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- JS Code View -->
|
|
|
|
|
+ <div id="js-code" class="code-view active">
|
|
|
|
|
+<span class="kwd">import</span> <span class="punc">{</span> animate <span class="punc">}</span> <span class="kwd">from</span> <span class="str">'animejs'</span><span class="punc">;</span>
|
|
|
|
|
+
|
|
|
|
|
+<span class="fun">animate</span><span class="punc">(</span><span class="str">'.square'</span><span class="punc">,</span> <span class="punc">{</span> x<span class="punc">:</span> <span class="str">'17rem'</span> <span class="punc">}</span><span class="punc">)</span><span class="punc">;</span>
|
|
|
|
|
+<span class="fun">animate</span><span class="punc">(</span><span class="str">'#css-selector-id'</span><span class="punc">,</span> <span class="punc">{</span> rotate<span class="punc">:</span> <span class="str">'1turn'</span> <span class="punc">}</span><span class="punc">)</span><span class="punc">;</span>
|
|
|
|
|
+<span class="fun">animate</span><span class="punc">(</span><span class="str">'.row:nth-child(3) .square'</span><span class="punc">,</span> <span class="punc">{</span> scale<span class="punc">:</span> <span class="punc">[</span><span class="num">1</span><span class="punc">,</span> <span class="num">.5</span><span class="punc">,</span> <span class="num">1</span><span class="punc">]</span> <span class="punc">}</span><span class="punc">)</span><span class="punc">;</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- HTML Code View -->
|
|
|
|
|
+ <div id="html-code" class="html-view">
|
|
|
|
|
+<span class="tag"><div</span> <span class="attr">class</span>=<span class="val">"medium row"</span><span class="tag">></span>
|
|
|
|
|
+ <span class="tag"><div</span> <span class="attr">class</span>=<span class="val">"square"</span><span class="tag">></div></span>
|
|
|
|
|
+<span class="tag"></div></span>
|
|
|
|
|
+<span class="tag"><div</span> <span class="attr">class</span>=<span class="val">"medium row"</span><span class="tag">></span>
|
|
|
|
|
+ <span class="tag"><div</span> <span class="attr">id</span>=<span class="val">"css-selector-id"</span> <span class="attr">class</span>=<span class="val">"square"</span><span class="tag">></div></span>
|
|
|
|
|
+<span class="tag"></div></span>
|
|
|
|
|
+<span class="tag"><div</span> <span class="attr">class</span>=<span class="val">"medium row"</span><span class="tag">></span>
|
|
|
|
|
+ <span class="tag"><div</span> <span class="attr">class</span>=<span class="val">"square"</span><span class="tag">></div></span>
|
|
|
|
|
+<span class="tag"></div></span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Live Demo -->
|
|
|
|
|
+ <div class="demo-visual">
|
|
|
|
|
+ <!-- Row 1 -->
|
|
|
|
|
+ <div class="medium row">
|
|
|
|
|
+ <div class="square"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <!-- Row 2 -->
|
|
|
|
|
+ <div class="medium row">
|
|
|
|
|
+ <div id="css-selector-id" class="square"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <!-- Row 3 -->
|
|
|
|
|
+ <div class="medium row">
|
|
|
|
|
+ <div class="square"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="action-bar">
|
|
|
|
|
+ <button class="play-btn" onclick="runDemo()">REPLAY</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <script src="../animal.js"></script>
|
|
|
|
|
+ <script>
|
|
|
|
|
+ function switchTab(tab) {
|
|
|
|
|
+ document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
|
|
|
|
+ document.querySelectorAll('.code-view, .html-view').forEach(v => v.classList.remove('active'));
|
|
|
|
|
+
|
|
|
|
|
+ if (tab === 'js') {
|
|
|
|
|
+ document.querySelector('.tabs .tab:nth-child(1)').classList.add('active');
|
|
|
|
|
+ document.getElementById('js-code').classList.add('active');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ document.querySelector('.tabs .tab:nth-child(2)').classList.add('active');
|
|
|
|
|
+ document.getElementById('html-code').classList.add('active');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function runDemo() {
|
|
|
|
|
+ // Reset styles first to allow replay
|
|
|
|
|
+ document.querySelectorAll('.square').forEach(el => {
|
|
|
|
|
+ el.style.transform = 'none';
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // To faithfully replicate the demo where animations appear independent
|
|
|
|
|
+ // but the code selector is broad ('.square'), we need to be careful.
|
|
|
|
|
+ // If we run animal.animate('.square', ...) it targets ALL squares.
|
|
|
|
|
+ // In the visual demo, likely all squares move RIGHT.
|
|
|
|
|
+ // Then the second one ALSO rotates.
|
|
|
|
|
+ // Then the third one ALSO scales.
|
|
|
|
|
+ // Let's implement exactly what the code says.
|
|
|
|
|
+
|
|
|
|
|
+ // 1. Move all squares
|
|
|
|
|
+ animal.animate('.square', {
|
|
|
|
|
+ x: '17rem',
|
|
|
|
|
+ duration: 1000,
|
|
|
|
|
+ easing: 'ease-out'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 2. Rotate the ID one
|
|
|
|
|
+ animal.animate('#css-selector-id', {
|
|
|
|
|
+ rotate: '1turn',
|
|
|
|
|
+ duration: 1000,
|
|
|
|
|
+ easing: 'ease-out'
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 3. Scale the 3rd row square
|
|
|
|
|
+ // Note: The HTML structure in demo-visual matches the selectors:
|
|
|
|
|
+ // .medium.row -> .square
|
|
|
|
|
+ // We use :nth-child(3) on the ROW, then find .square inside it.
|
|
|
|
|
+ // But wait, in .demo-visual, the rows are children of .demo-visual.
|
|
|
|
|
+ // row 1 is child 1
|
|
|
|
|
+ // row 2 is child 2
|
|
|
|
|
+ // row 3 is child 3
|
|
|
|
|
+ // So .medium.row:nth-child(3) should work relative to .demo-visual container if we scope it
|
|
|
|
|
+ // or if we use the global document selector properly.
|
|
|
|
|
+
|
|
|
|
|
+ // However, document.querySelectorAll('.row:nth-child(3)') might pick up other rows on the page if any.
|
|
|
|
|
+ // The class is "medium row".
|
|
|
|
|
+ // Let's use the specific selector from the code example.
|
|
|
|
|
+
|
|
|
|
|
+ // We need to be careful about ":nth-child(3)".
|
|
|
|
|
+ // The .medium.row elements are inside .demo-visual.
|
|
|
|
|
+ // If .demo-visual has other children (like text nodes or comments), index might differ.
|
|
|
|
|
+ // But browsers usually count element children for querySelector.
|
|
|
|
|
+
|
|
|
|
|
+ // Let's tweak the selector to ensure it hits OUR 3rd row.
|
|
|
|
|
+ // The code example says: '.row:nth-child(3) .square'
|
|
|
|
|
+ // In our HTML: <div class="medium row"> is the class.
|
|
|
|
|
+ // So '.row' works if it has that class.
|
|
|
|
|
+
|
|
|
|
|
+ animal.animate('.medium.row:nth-child(3) .square', {
|
|
|
|
|
+ scale: [1, .5, 1],
|
|
|
|
|
+ duration: 1000,
|
|
|
|
|
+ easing: 'ease-in-out'
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Auto run
|
|
|
|
|
+ setTimeout(runDemo, 500);
|
|
|
|
|
+
|
|
|
|
|
+ </script>
|
|
|
|
|
+</body>
|
|
|
|
|
+</html>
|