Created
June 22, 2026 07:19
-
-
Save amane-katagiri/6ba8407f657d451e38b756c5f1eafb34 to your computer and use it in GitHub Desktop.
あまねけ!おもしろCSS 7選 サンプルページ ⑦ CSSだけでランダムっぽいパラメータを使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>あまねけ!おもしろCSS 7選 サンプルページ ⑦ CSSだけでランダムっぽいパラメータを使う</title> | |
| <style> | |
| :root { | |
| --s: 1; | |
| } | |
| .random { | |
| --left: (mod(sin(var(--s) * 12.9898 * var(--i)) * 43758.5453, 1) * 95svw); | |
| --top: (mod(sin(var(--s) * 78.233 * var(--i)) * 43758.5453, 1) * 95svh); | |
| position: fixed; | |
| left: calc(var(--left)); | |
| top: calc(var(--top)); | |
| pointer-events: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div><input id="seed" type="range" min="1" max="10000" value="1"></div> | |
| <section> | |
| <div class="random" style="--i: 1;">①</div> | |
| <div class="random" style="--i: 2;">②</div> | |
| <div class="random" style="--i: 3;">③</div> | |
| <div class="random" style="--i: 4;">④</div> | |
| <div class="random" style="--i: 5;">⑤</div> | |
| <div class="random" style="--i: 6;">⑥</div> | |
| <div class="random" style="--i: 7;">⑦</div> | |
| <div class="random" style="--i: 8;">⑧</div> | |
| <div class="random" style="--i: 9;">⑨</div> | |
| <div class="random" style="--i: 10;">⑩</div> | |
| </section> | |
| <script> | |
| const slider = document.getElementById('seed'); | |
| slider.addEventListener('input', e => { | |
| const v = e.target.value; | |
| document.documentElement.style.setProperty('--s', e.target.value); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment