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">시작 번호 한 칸 이동</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 원작 · zip 에 SCSS·React 포함 · css 리스트 디자인 9종 — 마커가 계산으로 움직이는 목록 꾸미기
이 데모가 속한 글
css 리스트 디자인 9종 — 마커가 계산으로 움직이는 목록 꾸미기아홉 가지 리스트 마커 중 하나는 다이얼 각도 값이 항목마다 쌓이며 불릿이 시계처럼 돌고, 하나는 카운터 값이 자릿수별로 분해되어 숫자가 주행계처럼 굴러가고, 하나는 소수 판정 값에 따라 그 번호의 마커만 글로우가 이 글의 데모 전부 보기


