Trang chủJSBài viết
JS

Hàm hiệu ứng gõ chữ

20/03/2025 1002 lượt xem admin Cập nhật: 04/12/2025
5/5 - (641 bình chọn)
  • Cách 1: Vào Giao diệnTùy biếnAdvanced (Nâng cao) cuộn xuống Custom JS (JavaScript tùy chỉnh)
  • Cách 2: tạo file .js riêng và enqueue nó trong functions.php
  • Cách 3: Dùng UX Blocks (theme Flatsome) hoặc các plugin có mục dán code js như Code Snippets ,…
  • Cách 4: Riêng theme Flatsome: wp-admin/admin.php?page=optionsframework . Vào Flatsome  → Advanced Global Setting → Scripts
<script>
jQuery(document).ready(function($) {
if ($(".type-text").length) {
const type = document.querySelector(".type-text");
let listTexts = ["CHUYÊN NGHIỆP", "CHUẨN SEO", "LOAD NHANH", "GIÁ RẺ"];
let index = -1;
let current = 0;
function typeTextFunc() {
if (current === listTexts.length) {
current = 0
}
let typeText = setInterval( () => {
if (index == listTexts[current].length - 1) {
clearInterval(typeText);
clearTextFunc()
} else {
index++;
type.textContent += listTexts[current][index]
}
}
, 150)
}
function clearTextFunc() {
let clearText = setInterval( () => {
if (type.textContent.length == 0) {
clearInterval(clearText);
index = -1;
current++;
typeTextFunc()
} else {
type.textContent = type.textContent.slice(0, -1)
}
}
, 150)
}
typeTextFunc()
}
});
</script>

 

Chào ! Bạn thấy nội dung này thế nào?
webdy.vn
webdy.vn

Tạo web nhanh dùng thử miễn phí.

Chia sẻ ↗

Bài liên quan

×