document.addEventListener("DOMContentLoaded", function () { // Lấy tất cả các nút có class "aboutus-topanchor" var buttons = document.querySelectorAll(".aboutus-topanchor"); // Lặp qua từng nút và gắn sự kiện click buttons.forEach(function (button) { button.addEventListener("click", function (e) { e.preventDefault(); // Ngăn chặn hành động mặc định var target = document.querySelector(button.dataset.target); // Lấy phần tử mục tiêu từ data-target var offset = 50; // Khoảng cách bù trừ (tùy chỉnh) if (target) { // Tính toán vị trí cuộn var targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset; // Cuộn mượt đến vị trí chỉ định window.scrollTo({ top: targetPosition, behavior: "smooth", // Cuộn mượt }); } }); }); });