Spaces:
Running
Running
Upload 442 files
Browse files- static/assets/js/main.js +244 -244
static/assets/js/main.js
CHANGED
|
@@ -1,245 +1,245 @@
|
|
| 1 |
-
// Cho phép thanh trượt swiper trượt với tốc độ 3s
|
| 2 |
-
let swiperHome = new Swiper('.home__swiper', {
|
| 3 |
-
loop: true,
|
| 4 |
-
spaceBetween: -24,
|
| 5 |
-
grabCursor: true,
|
| 6 |
-
slidesPerView: 'auto',
|
| 7 |
-
centeredSlides: 'auto',
|
| 8 |
-
autoplay: {
|
| 9 |
-
delay: 3000,
|
| 10 |
-
disableOnInteraction: false,
|
| 11 |
-
},
|
| 12 |
-
breakpoints: {
|
| 13 |
-
1220: {
|
| 14 |
-
spaceBetween: -32,
|
| 15 |
-
},
|
| 16 |
-
},
|
| 17 |
-
});
|
| 18 |
-
|
| 19 |
-
// Hiệu ứng tăng dần số khi cuộn tới của Mission
|
| 20 |
-
//IntersectionObserver để theo dõi các phần tử cụ thể trên trang web (.aboutUS và .sumenh).
|
| 21 |
-
// Khi các phần tử này xuất hiện trong khung nhìn của người dùng (viewport), các hiệu ứng động sẽ được kích hoạt.
|
| 22 |
-
const counters = document.querySelectorAll('.counter');
|
| 23 |
-
let countersStarted = false;
|
| 24 |
-
|
| 25 |
-
const startCounters = () => {
|
| 26 |
-
counters.forEach(counter => {
|
| 27 |
-
counter.innerText = '0';
|
| 28 |
-
const updateCounter = () => {
|
| 29 |
-
const target = +counter.getAttribute('data-target');
|
| 30 |
-
const speed = +counter.getAttribute('data-speed');
|
| 31 |
-
const suffix = counter.getAttribute('data-suffix') || '';
|
| 32 |
-
const count = +counter.innerText.replace(suffix, '');
|
| 33 |
-
const increment = target / speed; // Điều chỉnh tốc độ cho từng phần tử
|
| 34 |
-
|
| 35 |
-
if (count < target) {
|
| 36 |
-
counter.innerText = Math.ceil(count + increment) + suffix;
|
| 37 |
-
setTimeout(updateCounter, 50); // Điều chỉnh giá trị thời gian để thay đổi tốc độ
|
| 38 |
-
} else {
|
| 39 |
-
counter.innerText = target + suffix;
|
| 40 |
-
}
|
| 41 |
-
};
|
| 42 |
-
updateCounter();
|
| 43 |
-
});
|
| 44 |
-
};
|
| 45 |
-
const observerAboutUS = new IntersectionObserver(entries => {
|
| 46 |
-
entries.forEach(entry => {
|
| 47 |
-
if (entry.isIntersecting) {
|
| 48 |
-
startTextAnimationAboutUS();
|
| 49 |
-
observerAboutUS.unobserve(entry.target); // Ngừng theo dõi sau khi hiệu ứng đã chạy
|
| 50 |
-
}
|
| 51 |
-
});
|
| 52 |
-
}, {threshold: 0.5});
|
| 53 |
-
|
| 54 |
-
observerAboutUS.observe(document.querySelector('.aboutUS'));
|
| 55 |
-
|
| 56 |
-
const observer = new IntersectionObserver(entries => {
|
| 57 |
-
entries.forEach(entry => {
|
| 58 |
-
if (entry.isIntersecting && !countersStarted) {
|
| 59 |
-
countersStarted = true;
|
| 60 |
-
startCounters();
|
| 61 |
-
startTextAnimation();
|
| 62 |
-
}
|
| 63 |
-
});
|
| 64 |
-
}, {threshold: 0.5});
|
| 65 |
-
observer.observe(document.querySelector('.sumenh'));
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
//Hiệu ứng hover vào mở link của Application
|
| 69 |
-
document.addEventListener("DOMContentLoaded", function () {
|
| 70 |
-
const box1 = document.getElementById("box1");
|
| 71 |
-
|
| 72 |
-
if (box1) {
|
| 73 |
-
box1.addEventListener("click", function () {
|
| 74 |
-
window.location.href = "https://example.com"; // Replace with the desired URL
|
| 75 |
-
});
|
| 76 |
-
}
|
| 77 |
-
});
|
| 78 |
-
|
| 79 |
-
//Chữ chạy text-sumenh-top phần About
|
| 80 |
-
const textElement = document.getElementById('about1');
|
| 81 |
-
const baseText = "Neural* AI Research Lab ";
|
| 82 |
-
const textArray = ["was established in 2019.", "has achieved a lot of success in applying AI to medical.", "has more than 10 trusted countries.", "has more than 3,000 satisfied customers."];
|
| 83 |
-
let arrayIndex = 0; //Các biến chỉ số: arrayIndex để theo dõi câu hiện tại trong mảng, charIndex để theo dõi ký tự hiện tại trong câu.
|
| 84 |
-
let charIndex = 0; //
|
| 85 |
-
|
| 86 |
-
//Hiển thị từng ký tự của câu hiện tại cho đến khi hoàn thành, sau đó chuyển sang hàm erase().
|
| 87 |
-
function type() {
|
| 88 |
-
if (charIndex < textArray[arrayIndex].length) //Kiểm tra xem câu hiện tại đã hoàn thành chưa
|
| 89 |
-
{
|
| 90 |
-
textElement.textContent = baseText + textArray[arrayIndex].substring(0, charIndex + 1);
|
| 91 |
-
charIndex++;
|
| 92 |
-
setTimeout(type, 100);
|
| 93 |
-
} else {
|
| 94 |
-
setTimeout(erase, 2000);
|
| 95 |
-
}
|
| 96 |
-
}
|
| 97 |
-
//Xóa từng ký tự của câu hiện tại cho đến khi hoàn thành, sau đó chuyển sang câu tiếp theo và quay lại hàm type().
|
| 98 |
-
function erase() {
|
| 99 |
-
if (charIndex > 0) {
|
| 100 |
-
textElement.textContent = baseText + textArray[arrayIndex].substring(0, charIndex - 1);
|
| 101 |
-
charIndex--;
|
| 102 |
-
setTimeout(erase, 50);
|
| 103 |
-
} else {
|
| 104 |
-
arrayIndex = (arrayIndex + 1) % textArray.length;
|
| 105 |
-
setTimeout(type, 1000);
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
document.addEventListener('DOMContentLoaded', function () {
|
| 109 |
-
setTimeout(type, 1000);
|
| 110 |
-
});
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
//Phần này giúp phần chuyển động từ trên xuống dưới cho research
|
| 114 |
-
//DOMContentLoaded: Đảm bảo mã chỉ chạy sau khi toàn bộ nội dung HTML đã được tải.
|
| 115 |
-
document.addEventListener('DOMContentLoaded', function () {
|
| 116 |
-
const researchSection = document.querySelector('.research');
|
| 117 |
-
function checkVisibility() //Hàm kiểm tra vị trí của phần tử so với khung nhìn của người dùng
|
| 118 |
-
{
|
| 119 |
-
const rect = researchSection.getBoundingClientRect(); //Lấy ra kích thước và vị trí của phần tử
|
| 120 |
-
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight); //Lấy ra chiều cao của khung nhìn
|
| 121 |
-
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) //Kiểm tra xem phần tử có nằm trong khung nhìn không
|
| 122 |
-
{
|
| 123 |
-
researchSection.classList.add('visible');
|
| 124 |
-
window.removeEventListener('scroll', checkVisibility);
|
| 125 |
-
}
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
window.addEventListener('scroll', checkVisibility);
|
| 129 |
-
checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
|
| 130 |
-
});
|
| 131 |
-
|
| 132 |
-
//Phần này giúp phần chuyển động tuwf trên xuống duưới trang load cho application
|
| 133 |
-
document.addEventListener('DOMContentLoaded', function () {
|
| 134 |
-
const researchSection = document.querySelector('.application');
|
| 135 |
-
|
| 136 |
-
function checkVisibility() {
|
| 137 |
-
const rect = researchSection.getBoundingClientRect();
|
| 138 |
-
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
|
| 139 |
-
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
|
| 140 |
-
researchSection.classList.add('visible');
|
| 141 |
-
window.removeEventListener('scroll', checkVisibility);
|
| 142 |
-
}
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
window.addEventListener('scroll', checkVisibility);
|
| 146 |
-
checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
|
| 147 |
-
});
|
| 148 |
-
|
| 149 |
-
//Phần này giúp phần chuyển động tuwf trên xuống duưới trang load cho contactUs
|
| 150 |
-
document.addEventListener('DOMContentLoaded', function () {
|
| 151 |
-
const researchSection = document.querySelector('.contactUS');
|
| 152 |
-
|
| 153 |
-
function checkVisibility() {
|
| 154 |
-
const rect = researchSection.getBoundingClientRect();
|
| 155 |
-
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
|
| 156 |
-
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
|
| 157 |
-
researchSection.classList.add('visible');
|
| 158 |
-
window.removeEventListener('scroll', checkVisibility);
|
| 159 |
-
}
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
window.addEventListener('scroll', checkVisibility);
|
| 163 |
-
checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
|
| 164 |
-
});
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
//Gạch chân nav bar khi cuộn xuống
|
| 168 |
-
document.addEventListener('DOMContentLoaded', function () //Đảm bảo mã chỉ chạy sau khi toàn bộ nội dung HTML đã được tải.
|
| 169 |
-
{
|
| 170 |
-
const sections = document.querySelectorAll('div[id$="Btn"]'); //Lấy ra tất cả các phần tử có id kết thúc bằng 'Btn'
|
| 171 |
-
const navLinks = document.querySelectorAll('nav ul li a'); //Lấy ra tất cả các thẻ a trong thẻ li của thẻ ul trong thẻ nav
|
| 172 |
-
|
| 173 |
-
function changeActiveNav() {
|
| 174 |
-
let index = sections.length;
|
| 175 |
-
|
| 176 |
-
while (--index && window.scrollY + 50 < sections[index].offsetTop) //Tìm ra phần tử đầu tiên mà người dùng đang nhìn thấy
|
| 177 |
-
{
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
navLinks.forEach((link) => link.classList.remove('active-nav'));
|
| 181 |
-
navLinks[index].classList.add('active-nav');
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
changeActiveNav();
|
| 185 |
-
window.addEventListener('scroll', changeActiveNav);
|
| 186 |
-
});
|
| 187 |
-
|
| 188 |
-
//Chatbot
|
| 189 |
-
|
| 190 |
-
document.getElementById('iconChatBot').addEventListener('click', function() {
|
| 191 |
-
const chatBotContent = document.getElementById('chatBotContent');
|
| 192 |
-
chatBotContent.style.display = chatBotContent.style.display === 'block' ? 'none' : 'block'; // Nếu điều kiện đúng (display hiện tại là 'block'), giá trị mới sẽ là 'none', tức là ẩn phần tử.
|
| 193 |
-
//Nếu điều kiện sai (display không phải là 'block'), giá trị mới sẽ là 'block', tức là hiển thị phần tử.
|
| 194 |
-
});
|
| 195 |
-
|
| 196 |
-
// Ngăn việc đóng form khi nhấp vào bên trong form
|
| 197 |
-
document.getElementById('chatBotContent').addEventListener('click', function(event) {
|
| 198 |
-
event.stopPropagation(); // Ngăn chặn sự kiện click từ lan rộng ra ngoài
|
| 199 |
-
});
|
| 200 |
-
|
| 201 |
-
// Xử lý sự kiện gửi form
|
| 202 |
-
document.getElementById('chatBotForm').addEventListener('submit', function(event) {
|
| 203 |
-
event.preventDefault();
|
| 204 |
-
const input = document.getElementById('chatBotInput').value;
|
| 205 |
-
if (input.trim() !== '') {
|
| 206 |
-
const chatBotMid = document.getElementById('chatBotmid');
|
| 207 |
-
|
| 208 |
-
const userMessage = document.createElement('div');
|
| 209 |
-
userMessage.style.textAlign = 'right';
|
| 210 |
-
userMessage.style.marginRight = '8px';
|
| 211 |
-
userMessage.style.color = 'black';
|
| 212 |
-
userMessage.textContent = input;
|
| 213 |
-
chatBotMid.appendChild(userMessage);
|
| 214 |
-
|
| 215 |
-
fetch('/send-message', {
|
| 216 |
-
method: 'POST',
|
| 217 |
-
headers: {
|
| 218 |
-
'Content-Type': 'application/json'
|
| 219 |
-
},
|
| 220 |
-
body: JSON.stringify({ message: input })
|
| 221 |
-
})
|
| 222 |
-
.then(response => response.json())
|
| 223 |
-
.then(data => {
|
| 224 |
-
const botResponse = document.createElement('div');
|
| 225 |
-
botResponse.style.textAlign = 'left';
|
| 226 |
-
botResponse.style.marginLeft = '8px';
|
| 227 |
-
botResponse.style.color = 'black';
|
| 228 |
-
botResponse.textContent = `Bot response: ${data.response}`;
|
| 229 |
-
chatBotMid.appendChild(botResponse);
|
| 230 |
-
|
| 231 |
-
// Scroll to the bottom when a new message is added
|
| 232 |
-
chatBotMid.scrollTop = chatBotMid.scrollHeight;
|
| 233 |
-
});
|
| 234 |
-
|
| 235 |
-
document.getElementById('chatBotInput').value = '';
|
| 236 |
-
}
|
| 237 |
-
});
|
| 238 |
-
|
| 239 |
-
// Đóng form khi nhấp ra ngoài
|
| 240 |
-
document.addEventListener('click', function(event) {
|
| 241 |
-
const chatBotContent = document.getElementById('chatBotContent');
|
| 242 |
-
if (!chatBotContent.contains(event.target) && !event.target.matches('#iconChatBot')) {
|
| 243 |
-
chatBotContent.style.display = 'none';
|
| 244 |
-
}
|
| 245 |
});
|
|
|
|
| 1 |
+
// Cho phép thanh trượt swiper trượt với tốc độ 3s
|
| 2 |
+
let swiperHome = new Swiper('.home__swiper', {
|
| 3 |
+
loop: true,
|
| 4 |
+
spaceBetween: -24,
|
| 5 |
+
grabCursor: true,
|
| 6 |
+
slidesPerView: 'auto',
|
| 7 |
+
centeredSlides: 'auto',
|
| 8 |
+
autoplay: {
|
| 9 |
+
delay: 3000,
|
| 10 |
+
disableOnInteraction: false,
|
| 11 |
+
},
|
| 12 |
+
breakpoints: {
|
| 13 |
+
1220: {
|
| 14 |
+
spaceBetween: -32,
|
| 15 |
+
},
|
| 16 |
+
},
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
// Hiệu ứng tăng dần số khi cuộn tới của Mission
|
| 20 |
+
//IntersectionObserver để theo dõi các phần tử cụ thể trên trang web (.aboutUS và .sumenh).
|
| 21 |
+
// Khi các phần tử này xuất hiện trong khung nhìn của người dùng (viewport), các hiệu ứng động sẽ được kích hoạt.
|
| 22 |
+
const counters = document.querySelectorAll('.counter');
|
| 23 |
+
let countersStarted = false;
|
| 24 |
+
|
| 25 |
+
const startCounters = () => {
|
| 26 |
+
counters.forEach(counter => {
|
| 27 |
+
counter.innerText = '0';
|
| 28 |
+
const updateCounter = () => {
|
| 29 |
+
const target = +counter.getAttribute('data-target');
|
| 30 |
+
const speed = +counter.getAttribute('data-speed');
|
| 31 |
+
const suffix = counter.getAttribute('data-suffix') || '';
|
| 32 |
+
const count = +counter.innerText.replace(suffix, '');
|
| 33 |
+
const increment = target / speed; // Điều chỉnh tốc độ cho từng phần tử
|
| 34 |
+
|
| 35 |
+
if (count < target) {
|
| 36 |
+
counter.innerText = Math.ceil(count + increment) + suffix;
|
| 37 |
+
setTimeout(updateCounter, 50); // Điều chỉnh giá trị thời gian để thay đổi tốc độ
|
| 38 |
+
} else {
|
| 39 |
+
counter.innerText = target + suffix;
|
| 40 |
+
}
|
| 41 |
+
};
|
| 42 |
+
updateCounter();
|
| 43 |
+
});
|
| 44 |
+
};
|
| 45 |
+
const observerAboutUS = new IntersectionObserver(entries => {
|
| 46 |
+
entries.forEach(entry => {
|
| 47 |
+
if (entry.isIntersecting) {
|
| 48 |
+
startTextAnimationAboutUS();
|
| 49 |
+
observerAboutUS.unobserve(entry.target); // Ngừng theo dõi sau khi hiệu ứng đã chạy
|
| 50 |
+
}
|
| 51 |
+
});
|
| 52 |
+
}, {threshold: 0.5});
|
| 53 |
+
|
| 54 |
+
observerAboutUS.observe(document.querySelector('.aboutUS'));
|
| 55 |
+
|
| 56 |
+
const observer = new IntersectionObserver(entries => {
|
| 57 |
+
entries.forEach(entry => {
|
| 58 |
+
if (entry.isIntersecting && !countersStarted) {
|
| 59 |
+
countersStarted = true;
|
| 60 |
+
startCounters();
|
| 61 |
+
startTextAnimation();
|
| 62 |
+
}
|
| 63 |
+
});
|
| 64 |
+
}, {threshold: 0.5});
|
| 65 |
+
observer.observe(document.querySelector('.sumenh'));
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
//Hiệu ứng hover vào mở link của Application
|
| 69 |
+
document.addEventListener("DOMContentLoaded", function () {
|
| 70 |
+
const box1 = document.getElementById("box1");
|
| 71 |
+
|
| 72 |
+
if (box1) {
|
| 73 |
+
box1.addEventListener("click", function () {
|
| 74 |
+
window.location.href = "https://example.com"; // Replace with the desired URL
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
//Chữ chạy text-sumenh-top phần About
|
| 80 |
+
const textElement = document.getElementById('about1');
|
| 81 |
+
const baseText = "Neural* AI Research Lab ";
|
| 82 |
+
const textArray = ["was established in 2019.", "has achieved a lot of success in applying AI to medical.", "has more than 10 trusted countries.", "has more than 3,000 satisfied customers."];
|
| 83 |
+
let arrayIndex = 0; //Các biến chỉ số: arrayIndex để theo dõi câu hiện tại trong mảng, charIndex để theo dõi ký tự hiện tại trong câu.
|
| 84 |
+
let charIndex = 0; //
|
| 85 |
+
|
| 86 |
+
//Hiển thị từng ký tự của câu hiện tại cho đến khi hoàn thành, sau đó chuyển sang hàm erase().
|
| 87 |
+
function type() {
|
| 88 |
+
if (charIndex < textArray[arrayIndex].length) //Kiểm tra xem câu hiện tại đã hoàn thành chưa
|
| 89 |
+
{
|
| 90 |
+
textElement.textContent = baseText + textArray[arrayIndex].substring(0, charIndex + 1);
|
| 91 |
+
charIndex++;
|
| 92 |
+
setTimeout(type, 100);
|
| 93 |
+
} else {
|
| 94 |
+
setTimeout(erase, 2000);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
//Xóa từng ký tự của câu hiện tại cho đến khi hoàn thành, sau đó chuyển sang câu tiếp theo và quay lại hàm type().
|
| 98 |
+
function erase() {
|
| 99 |
+
if (charIndex > 0) {
|
| 100 |
+
textElement.textContent = baseText + textArray[arrayIndex].substring(0, charIndex - 1);
|
| 101 |
+
charIndex--;
|
| 102 |
+
setTimeout(erase, 50);
|
| 103 |
+
} else {
|
| 104 |
+
arrayIndex = (arrayIndex + 1) % textArray.length;
|
| 105 |
+
setTimeout(type, 1000);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 109 |
+
setTimeout(type, 1000);
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
//Phần này giúp phần chuyển động từ trên xuống dưới cho research
|
| 114 |
+
//DOMContentLoaded: Đảm bảo mã chỉ chạy sau khi toàn bộ nội dung HTML đã được tải.
|
| 115 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 116 |
+
const researchSection = document.querySelector('.research');
|
| 117 |
+
function checkVisibility() //Hàm kiểm tra vị trí của phần tử so với khung nhìn của người dùng
|
| 118 |
+
{
|
| 119 |
+
const rect = researchSection.getBoundingClientRect(); //Lấy ra kích thước và vị trí của phần tử
|
| 120 |
+
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight); //Lấy ra chiều cao của khung nhìn
|
| 121 |
+
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) //Kiểm tra xem phần tử có nằm trong khung nhìn không
|
| 122 |
+
{
|
| 123 |
+
researchSection.classList.add('visible');
|
| 124 |
+
window.removeEventListener('scroll', checkVisibility);
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
window.addEventListener('scroll', checkVisibility);
|
| 129 |
+
checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
//Phần này giúp phần chuyển động tuwf trên xuống duưới trang load cho application
|
| 133 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 134 |
+
const researchSection = document.querySelector('.application');
|
| 135 |
+
|
| 136 |
+
function checkVisibility() {
|
| 137 |
+
const rect = researchSection.getBoundingClientRect();
|
| 138 |
+
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
|
| 139 |
+
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
|
| 140 |
+
researchSection.classList.add('visible');
|
| 141 |
+
window.removeEventListener('scroll', checkVisibility);
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
window.addEventListener('scroll', checkVisibility);
|
| 146 |
+
checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
|
| 147 |
+
});
|
| 148 |
+
|
| 149 |
+
//Phần này giúp phần chuyển động tuwf trên xuống duưới trang load cho contactUs
|
| 150 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 151 |
+
const researchSection = document.querySelector('.contactUS');
|
| 152 |
+
|
| 153 |
+
function checkVisibility() {
|
| 154 |
+
const rect = researchSection.getBoundingClientRect();
|
| 155 |
+
const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
|
| 156 |
+
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
|
| 157 |
+
researchSection.classList.add('visible');
|
| 158 |
+
window.removeEventListener('scroll', checkVisibility);
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
window.addEventListener('scroll', checkVisibility);
|
| 163 |
+
checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
|
| 164 |
+
});
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
//Gạch chân nav bar khi cuộn xuống
|
| 168 |
+
document.addEventListener('DOMContentLoaded', function () //Đảm bảo mã chỉ chạy sau khi toàn bộ nội dung HTML đã được tải.
|
| 169 |
+
{
|
| 170 |
+
const sections = document.querySelectorAll('div[id$="Btn"]'); //Lấy ra tất cả các phần tử có id kết thúc bằng 'Btn'
|
| 171 |
+
const navLinks = document.querySelectorAll('nav ul li a'); //Lấy ra tất cả các thẻ a trong thẻ li của thẻ ul trong thẻ nav
|
| 172 |
+
|
| 173 |
+
function changeActiveNav() {
|
| 174 |
+
let index = sections.length;
|
| 175 |
+
|
| 176 |
+
while (--index && window.scrollY + 50 < sections[index].offsetTop) //Tìm ra phần tử đầu tiên mà người dùng đang nhìn thấy
|
| 177 |
+
{
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
navLinks.forEach((link) => link.classList.remove('active-nav'));
|
| 181 |
+
navLinks[index].classList.add('active-nav');
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
changeActiveNav();
|
| 185 |
+
window.addEventListener('scroll', changeActiveNav);
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
//Chatbot
|
| 189 |
+
|
| 190 |
+
document.getElementById('iconChatBot').addEventListener('click', function() {
|
| 191 |
+
const chatBotContent = document.getElementById('chatBotContent');
|
| 192 |
+
chatBotContent.style.display = chatBotContent.style.display === 'block' ? 'none' : 'block'; // Nếu điều kiện đúng (display hiện tại là 'block'), giá trị mới sẽ là 'none', tức là ẩn phần tử.
|
| 193 |
+
//Nếu điều kiện sai (display không phải là 'block'), giá trị mới sẽ là 'block', tức là hiển thị phần tử.
|
| 194 |
+
});
|
| 195 |
+
|
| 196 |
+
// Ngăn việc đóng form khi nhấp vào bên trong form
|
| 197 |
+
document.getElementById('chatBotContent').addEventListener('click', function(event) {
|
| 198 |
+
event.stopPropagation(); // Ngăn chặn sự kiện click từ lan rộng ra ngoài
|
| 199 |
+
});
|
| 200 |
+
|
| 201 |
+
// Xử lý sự kiện gửi form
|
| 202 |
+
document.getElementById('chatBotForm').addEventListener('submit', function(event) {
|
| 203 |
+
event.preventDefault();
|
| 204 |
+
const input = document.getElementById('chatBotInput').value;
|
| 205 |
+
if (input.trim() !== '') {
|
| 206 |
+
const chatBotMid = document.getElementById('chatBotmid');
|
| 207 |
+
|
| 208 |
+
const userMessage = document.createElement('div');
|
| 209 |
+
userMessage.style.textAlign = 'right';
|
| 210 |
+
userMessage.style.marginRight = '8px';
|
| 211 |
+
userMessage.style.color = 'black';
|
| 212 |
+
userMessage.textContent = input;
|
| 213 |
+
chatBotMid.appendChild(userMessage);
|
| 214 |
+
|
| 215 |
+
fetch('/send-message', {
|
| 216 |
+
method: 'POST',
|
| 217 |
+
headers: {
|
| 218 |
+
'Content-Type': 'application/json'
|
| 219 |
+
},
|
| 220 |
+
body: JSON.stringify({ message: input })
|
| 221 |
+
})
|
| 222 |
+
.then(response => response.json())
|
| 223 |
+
.then(data => {
|
| 224 |
+
const botResponse = document.createElement('div');
|
| 225 |
+
botResponse.style.textAlign = 'left';
|
| 226 |
+
botResponse.style.marginLeft = '8px';
|
| 227 |
+
botResponse.style.color = 'black';
|
| 228 |
+
botResponse.textContent = `Bot response: ${data.response}`;
|
| 229 |
+
chatBotMid.appendChild(botResponse);
|
| 230 |
+
|
| 231 |
+
// Scroll to the bottom when a new message is added
|
| 232 |
+
chatBotMid.scrollTop = chatBotMid.scrollHeight;
|
| 233 |
+
});
|
| 234 |
+
|
| 235 |
+
document.getElementById('chatBotInput').value = '';
|
| 236 |
+
}
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
// Đóng form khi nhấp ra ngoài
|
| 240 |
+
document.addEventListener('click', function(event) {
|
| 241 |
+
const chatBotContent = document.getElementById('chatBotContent');
|
| 242 |
+
if (!chatBotContent.contains(event.target) && !event.target.matches('#iconChatBot')) {
|
| 243 |
+
chatBotContent.style.display = 'none';
|
| 244 |
+
}
|
| 245 |
});
|