01Con trỏ nhấp nháy
Đặt một thanh con trỏ rộng bằng một ký tự ngay sau chữ vừa gõ xong, cho opacity nhấp nháy bằng step-end để trông giống con trỏ gõ chữ thật.
Dùng choNhấn mạnh placeholder của form, trạng thái chờ của ô chat
steps(2, jump-none)opacity 깜빡임@keyframes caret-blink

<main class="stage">
<p class="line"><span class="line__text">Tôi có thể giúp gì cho bạn?</span><span class="line__caret" aria-hidden="true"></span></p>
</main>@use "../../../../site/static/demo-tokens" as *;
$duration: $dur-base; // 깜빡임 한 주기
$easing: steps(2, jump-none); // 뚝뚝 끊어 깜빡이게 (부드럽게 섞지 않는다)
$color: $subject-blue; // 커서 색
@include stage($stage-ink);
.line {
display: flex;
align-items: baseline;
margin: 0;
font-weight: 700; font-size: clamp(20px, 5.6vw, 34px); line-height: 1.4; font-family: inherit;
color: $subject-cream;
&__caret {
display: inline-block;
width: clamp(8px, 2.6vw, 14px);
height: 1.3em;
margin-left: clamp(2px, 1vw, 6px);
background: $color;
animation: caret-blink $duration $easing infinite;
}
}
@keyframes caret-blink {
from { opacity: 1; }
to { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.line__caret { animation: none; opacity: 1; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.line {
display: flex;
align-items: baseline;
margin: 0;
font-weight: 700;
font-size: clamp(20px, 5.6vw, 34px);
line-height: 1.4;
font-family: inherit;
color: #fff7e6;
}
.line__caret {
display: inline-block;
width: clamp(8px, 2.6vw, 14px);
height: 1.3em;
margin-left: clamp(2px, 1vw, 6px);
background: #2f6df6;
animation: caret-blink 300ms steps(2, jump-none) infinite;
}
@keyframes caret-blink {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.line__caret {
animation: none;
opacity: 1;
}
}import type { CSSProperties } from "react";
import styles from "./CaretBlink.module.scss";
export type CaretBlinkProps = {
text: string;
/** 깜빡임 한 주기 (기본 300ms) */
duration?: number;
color?: string;
};
export default function CaretBlink({ text, duration = 300, color = "#2f6df6" }: CaretBlinkProps) {
const vars = { "--duration": `${duration}ms`, "--color": color } as CSSProperties;
return (
<p className={styles.line} style={vars}>
<span className={styles.text}>{text}</span>
<span className={styles.caret} aria-hidden="true" />
</p>
);
}01 Con trỏ nhấp nháy — Diện tích đo được 0.316% · khung hình chuyển động 11/23Nguyên tác GODRICH · SCSS và React nằm trong tệp zip · 9 kiểu css typing animation, copy dán là chạy
Bài viết chứa demo này
9 kiểu css typing animation, copy dán là chạyCss typing animation là hiệu ứng mô phỏng việc gõ chữ bằng CSS thuần, dựng bằng steps() và một con trỏ nhấp nháy thay ch Xem tất cả demo trong bài này


