05素数グローマーカー — 素数判定の値を計算し、該当番号だけが光る方式
各項目番号に素数判定の計算を回し、判定を通過した番号のマーカーだけが光を放ち、残りは静かに留まります。
使いどころ学習コンテンツの目次、強調ピックリスト
counterbox-shadow$subject-blue-deep

<main class="stage">
<div class="wrap is-demo" id="wrap">
<ol class="prime-list" id="list" start="1">
<li>変数と型</li>
<li>条件と繰り返し</li>
<li>関数とスコープ</li>
<li>配列とオブジェクト</li>
<li>非同期処理</li>
<li>モジュールシステム</li>
<li>テスト作成</li>
</ol>
<button class="shift" id="shift" type="button">開始番号を1つ動かす</button>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 계산 겹은 index.html 의 isPrime() 시행 나눗셈 판정에 있다 — 여기는 번호 상자·글로우 애니메이션만 맡는다.
// ::marker 는 box-shadow(글로우)·animation 을 지원하지 않는다(color·content·font 뿐) — list-style:none 으로
// 네이티브 번호를 지우고 counter() 값을 ::before 콘텐츠로 다시 그려 그 위에 글로우를 건다.
@include stage($stage-paper);
.prime-list {
list-style: none;
counter-reset: item;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: $sp-2;
width: 230px;
}
.prime-list li {
counter-increment: item;
position: relative;
padding-left: 32px;
min-height: 22px;
display: flex;
align-items: center;
color: $subject-ink;
font-size: 12px;
}
.prime-list li::before {
content: counter(item);
position: absolute;
left: 0;
top: 50%;
width: 22px;
height: 22px;
margin-top: -11px;
border-radius: 50%;
background: $subject-blue-deep;
color: $subject-cream;
font-size: 11px;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 0 0 0 rgba($subject-blue-deep, 0);
}
.prime-list li.is-prime::before {
animation: primePulse $dur-loop $ease-out infinite;
}
@keyframes primePulse {
0%, 100% { box-shadow: 0 0 0 0 rgba($subject-blue-deep, .55); }
50% { box-shadow: 0 0 0 7px rgba($subject-blue-deep, 0); }
}
.shift {
appearance: none;
border: none;
margin-top: $sp-4;
padding: $sp-2 $sp-4;
border-radius: $r-control;
background: $subject-blue-deep;
color: $subject-cream;
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: transform $dur-instant $ease-out;
&:hover { transform: translateY(-1px); }
&:active { transform: scale(.96); }
&:focus-visible { outline: 2px solid $subject-blue-light; outline-offset: 2px; }
}
@media (max-width: 340px) {
.prime-list {
width: 260px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: $sp-1;
}
.prime-list li { font-size: 10px; min-height: 20px; padding-left: 24px; }
.prime-list li::before { width: 18px; height: 18px; margin-top: -9px; font-size: 10px; }
.shift { margin-top: $sp-2; padding: $sp-1 $sp-3; }
}
@media (prefers-reduced-motion: reduce) {
.prime-list li.is-prime::before { animation: none; box-shadow: 0 0 0 4px rgba($subject-blue-deep, .35); }
.shift { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.prime-list {
list-style: none;
counter-reset: item;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 8px;
width: 230px;
}
.prime-list li {
counter-increment: item;
position: relative;
padding-left: 32px;
min-height: 22px;
display: flex;
align-items: center;
color: #17141a;
font-size: 12px;
}
.prime-list li::before {
content: counter(item);
position: absolute;
left: 0;
top: 50%;
width: 22px;
height: 22px;
margin-top: -11px;
border-radius: 50%;
background: #0a4fe8;
color: #fff7e6;
font-size: 11px;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 0 0 0 rgba(10, 79, 232, 0);
}
.prime-list li.is-prime::before {
animation: primePulse 2s ease-out infinite;
}
@keyframes primePulse {
0%, 100% {
box-shadow: 0 0 0 0 rgba(10, 79, 232, 0.55);
}
50% {
box-shadow: 0 0 0 7px rgba(10, 79, 232, 0);
}
}
.shift {
appearance: none;
border: none;
margin-top: 16px;
padding: 8px 16px;
border-radius: 12px;
background: #0a4fe8;
color: #fff7e6;
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: transform 140ms ease-out;
}
.shift:hover {
transform: translateY(-1px);
}
.shift:active {
transform: scale(0.96);
}
.shift:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
}
@media (max-width: 340px) {
.prime-list {
width: 260px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 4px;
}
.prime-list li {
font-size: 10px;
min-height: 20px;
padding-left: 24px;
}
.prime-list li::before {
width: 18px;
height: 18px;
margin-top: -9px;
font-size: 10px;
}
.shift {
margin-top: 8px;
padding: 4px 12px;
}
}
@media (prefers-reduced-motion: reduce) {
.prime-list li.is-prime::before {
animation: none;
box-shadow: 0 0 0 4px rgba(10, 79, 232, 0.35);
}
.shift {
transition: none;
}
}(function () {
var GLOW_PULSE_MS = 1100;
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var wrap = document.getElementById('wrap');
var list = document.getElementById('list');
var items = Array.prototype.slice.call(list.querySelectorAll('li'));
var button = document.getElementById('shift');
var isDemo = true;
var start = 1;
// 계산 겹: 각 항목 번호에 소수 판정을 직접 계산한다 — 미리 정해둔 목록이 아니라 실행마다 다시 돈다.
function isPrime(n) {
if (n < 2) return false;
for (var d = 2; d * d <= n; d++) {
if (n % d === 0) return false;
}
return true;
}
function recompute() {
list.setAttribute('start', String(start));
items.forEach(function (li, i) {
var n = start + i;
li.classList.toggle('is-prime', isPrime(n));
});
}
function human() { if (isDemo) { wrap.classList.remove('is-demo'); isDemo = false; } }
button.addEventListener('click', function () {
human();
start += 1;
recompute();
});
var last = 0;
var STEP_MS = 900;
function loop(ts) {
if (!last) last = ts;
if (isDemo && !reduce && ts - last >= STEP_MS) {
last = ts;
start += 1;
recompute();
}
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
recompute();
})();// PrimeGlowMarker — vanilla 판(run/373/demo/05-list-style-number-prime-glow/index.html) 의 React 포트.
// ::marker 는 box-shadow(글로우)·animation 을 지원하지 않는다(color·content·font 뿐) — counter() 값을
// ::before 콘텐츠로 다시 그려 그 위에 글로우를 건다. 소수 판정은 매번 직접 계산한다.
import { useEffect, useRef } from "react";
import styles from "./PrimeGlowMarker.module.scss";
type Box<T> = { current: T };
const STEP_MS = 900; // 자동 루프에서 시작 번호를 한 칸 옮기는 간격
const LESSONS = ["변수와 타입", "조건과 반복", "함수와 스코프", "배열과 객체", "비동기 처리", "모듈 시스템", "테스트 작성"];
export default function PrimeGlowMarker() {
const rootRef = useRef(null) as unknown as Box<HTMLDivElement>;
const listRef = useRef(null) as unknown as Box<HTMLOListElement>;
const rafRef = useRef(0) as unknown as Box<number>;
useEffect(() => {
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const root = rootRef.current;
const list = listRef.current;
if (!root || !list) return;
const items = Array.prototype.slice.call(list.querySelectorAll("li"));
let isDemo = true;
let start = 1;
// 계산 겹: 각 항목 번호에 소수 판정을 직접 계산한다 — 미리 정해둔 목록이 아니라 실행마다 다시 돈다.
function isPrime(n: number) {
if (n < 2) return false;
for (let d = 2; d * d <= n; d++) {
if (n % d === 0) return false;
}
return true;
}
function recompute() {
list!.setAttribute("start", String(start));
items.forEach(function (li: HTMLElement, i: number) {
const n = start + i;
li.classList.toggle("is-prime", isPrime(n));
});
}
function human() { if (isDemo) { root!.classList.remove(styles.isDemo); isDemo = false; } }
function onClick() {
human();
start += 1;
recompute();
}
root!.addEventListener("click", onClick);
let last = 0;
function loop(ts: number) {
if (!last) last = ts;
if (isDemo && !reduce && ts - last >= STEP_MS) {
last = ts;
start += 1;
recompute();
}
rafRef.current = requestAnimationFrame(loop);
}
rafRef.current = requestAnimationFrame(loop);
recompute();
return () => {
root!.removeEventListener("click", onClick);
cancelAnimationFrame(rafRef.current);
};
}, []);
return (
<main className={styles.stage}>
<div className={styles.wrap + " " + styles.isDemo} ref={rootRef}>
<ol className={styles.primeList} ref={listRef} start={1}>
{LESSONS.map(function (l) { return <li key={l}>{l}</li>; })}
</ol>
<button className={styles.shift} type="button">시작 번호 한 칸 이동</button>
</div>
</main>
);
}05 素数グローマーカー — 素数判定の値を計算し、該当番号だけが光る方式 — 計測 累積面積 2.419% · 動いたフレーム 20/23GODRICH オリジナル · SCSS と React は zip に同梱 · css リスト デザイン 9選 — マーカーが計算で動く箇条書きの装飾
このデモが属する記事
css リスト デザイン 9選 — マーカーが計算で動く箇条書きの装飾9つのリストマーカーのうち、1つはダイヤル角度の値が項目ごとに積み、箇条書きの点が時計のように回り、1つはカウンター値が桁ごとに分解されて数字が走行計のように転がり、1つは素数判定の値によってその番号のマーカーだけが光を放ちます。この9つは この記事のデモをすべて見る


