พรีวิวเทอร์มินัลแบบเรียลไทม์
รับชมข้อความพิมพ์และลบอย่างราบรื่นในกรอบหน้าต่างเทอร์มินัลสีเข้มทันสมัย
เอฟเฟกต์พิมพ์ดีด
ปรับแต่งและดูตัวอย่างภาพเคลื่อนไหวพิมพ์ข้อความและลบข้อความแบบเรียลไทม์ พร้อมคัดลอกโค้ดสำหรับ React, JavaScript และ CSS
import React, { useState, useEffect } from "react";
export function Typewriter() {
const words = [
"Hello, World! 👋",
"Build beautiful web applications.",
"100% Client-Side Typewriter Effect.",
"Fast, smooth, and fully customizable."
];
const [currentText, setCurrentText] = useState("");
const [wordIdx, setWordIdx] = useState(0);
const [isDeleting, setIsDeleting] = useState(false);
useEffect(() => {
const currentWord = words[wordIdx % words.length];
let timer;
if (!isDeleting) {
if (currentText.length < currentWord.length) {
timer = setTimeout(() => {
setCurrentText(currentWord.slice(0, currentText.length + 1));
}, 80);
} else {
timer = setTimeout(() => setIsDeleting(true), 1500);
}
} else {
if (currentText.length > 0) {
timer = setTimeout(() => {
setCurrentText(currentWord.slice(0, currentText.length - 1));
}, 40);
} else {
setIsDeleting(false);
setWordIdx((prev) => (prev + 1) % words.length);
}
}
return () => clearTimeout(timer);
}, [currentText, isDeleting, wordIdx]);
return (
<div className="font-mono text-2xl font-bold text-slate-100 flex items-center">
<span>{currentText}</span>
<span className="animate-pulse ml-0.5 text-blue-500">|</span>
</div>
);
}สร้างข้อความเคลื่อนไหวที่น่าดึงดูดสำหรับส่วนหัวของเว็บไซต์และหน้าแลนดิ้งเพจ
รับชมข้อความพิมพ์และลบอย่างราบรื่นในกรอบหน้าต่างเทอร์มินัลสีเข้มทันสมัย
ปรับความเร็วในการพิมพ์ การลบ เวลาหน่วง และเลือกรูปแบบเคอร์เซอร์กะพริบได้ตามใจชอบ
สร้างโค้ดสำเร็จรูปที่พร้อมนำไปใช้งานในโปรเจกต์เว็บของคุณได้ทันที
ต้องการฟื้นฟูจิตใจ 2 นาทีใช่ไหม? กระโดดเข้าสู่เกมปริศนาสุดคลาสสิกในเบราว์เซอร์ของคุณ