File size: 10,636 Bytes
b314bc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93f2cac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Cho phép thanh trượt swiper trượt với tốc độ 3s
let swiperHome = new Swiper('.home__swiper', {
    loop: true,
    spaceBetween: -24,
    grabCursor: true,
    slidesPerView: 'auto',
    centeredSlides: 'auto',
    autoplay: {
        delay: 3000,
        disableOnInteraction: false,
    },
    breakpoints: {
        1220: {
            spaceBetween: -32,
        },
    },
});

// Hiệu ứng tăng dần số khi cuộn tới của Mission
//IntersectionObserver để theo dõi các phần tử cụ thể trên trang web (.aboutUS và .sumenh).
// 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.
const counters = document.querySelectorAll('.counter');
let countersStarted = false;

const startCounters = () => {
    counters.forEach(counter => {
        counter.innerText = '0';
        const updateCounter = () => {
            const target = +counter.getAttribute('data-target');
            const speed = +counter.getAttribute('data-speed');
            const suffix = counter.getAttribute('data-suffix') || '';
            const count = +counter.innerText.replace(suffix, '');
            const increment = target / speed; // Điều chỉnh tốc độ cho từng phần tử

            if (count < target) {
                counter.innerText = Math.ceil(count + increment) + suffix;
                setTimeout(updateCounter, 50); // Điều chỉnh giá trị thời gian để thay đổi tốc độ
            } else {
                counter.innerText = target + suffix;
            }
        };
        updateCounter();
    });
};
const observerAboutUS = new IntersectionObserver(entries => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            startTextAnimationAboutUS();
            observerAboutUS.unobserve(entry.target); // Ngừng theo dõi sau khi hiệu ứng đã chạy
        }
    });
}, {threshold: 0.5});

observerAboutUS.observe(document.querySelector('.aboutUS'));

const observer = new IntersectionObserver(entries => {
    entries.forEach(entry => {
        if (entry.isIntersecting && !countersStarted) {
            countersStarted = true;
            startCounters();
            startTextAnimation();
        }
    });
}, {threshold: 0.5});
observer.observe(document.querySelector('.sumenh'));


//Hiệu ứng hover vào mở link của Application
document.addEventListener("DOMContentLoaded", function () {
    const box1 = document.getElementById("box1");

    if (box1) {
        box1.addEventListener("click", function () {
            window.location.href = "https://example.com"; // Replace with the desired URL
        });
    }
});

//Chữ chạy text-sumenh-top phần About
const textElement = document.getElementById('about1');
const baseText = "Neural* AI Research Lab ";
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."];
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.
let charIndex = 0; //

//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().
function type() {
    if (charIndex < textArray[arrayIndex].length) //Kiểm tra xem câu hiện tại đã hoàn thành chưa
    {
        textElement.textContent = baseText + textArray[arrayIndex].substring(0, charIndex + 1);
        charIndex++;
        setTimeout(type, 100);
    } else {
        setTimeout(erase, 2000);
    }
}
//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().
function erase() {
    if (charIndex > 0) {
        textElement.textContent = baseText + textArray[arrayIndex].substring(0, charIndex - 1);
        charIndex--;
        setTimeout(erase, 50);
    } else {
        arrayIndex = (arrayIndex + 1) % textArray.length;
        setTimeout(type, 1000);
    }
}
document.addEventListener('DOMContentLoaded', function () {
    setTimeout(type, 1000);
});


//Phần này giúp phần chuyển động từ trên xuống dưới cho research
//DOMContentLoaded: Đảm bảo mã chỉ chạy sau khi toàn bộ nội dung HTML đã được tải.
document.addEventListener('DOMContentLoaded', function () {
    const researchSection = document.querySelector('.research');
    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
    {
        const rect = researchSection.getBoundingClientRect(); //Lấy ra kích thước và vị trí của phần tử
        const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight); //Lấy ra chiều cao của khung nhìn
        if (!(rect.bottom < 0 || rect.top - viewHeight >= 0))  //Kiểm tra xem phần tử có nằm trong khung nhìn không
        {
            researchSection.classList.add('visible');
            window.removeEventListener('scroll', checkVisibility);
        }
    }

    window.addEventListener('scroll', checkVisibility);
    checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
});

//Phần này giúp phần chuyển động tuwf trên xuống duưới trang load cho application
document.addEventListener('DOMContentLoaded', function () {
    const researchSection = document.querySelector('.application');

    function checkVisibility() {
        const rect = researchSection.getBoundingClientRect();
        const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
        if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
            researchSection.classList.add('visible');
            window.removeEventListener('scroll', checkVisibility);
        }
    }

    window.addEventListener('scroll', checkVisibility);
    checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
});

//Phần này giúp phần chuyển động tuwf trên xuống duưới trang load cho contactUs
document.addEventListener('DOMContentLoaded', function () {
    const researchSection = document.querySelector('.contactUS');

    function checkVisibility() {
        const rect = researchSection.getBoundingClientRect();
        const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
        if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
            researchSection.classList.add('visible');
            window.removeEventListener('scroll', checkVisibility);
        }
    }

    window.addEventListener('scroll', checkVisibility);
    checkVisibility(); // Gọi hàm ngay khi trang tải để kiểm tra vị trí ban đầu
});


//Gạch chân nav bar khi cuộn xuống
document.addEventListener('DOMContentLoaded', function () //Đảm bảo mã chỉ chạy sau khi toàn bộ nội dung HTML đã được tải.
{
    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'
    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

    function changeActiveNav() {
        let index = sections.length;

        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
        {
        }

        navLinks.forEach((link) => link.classList.remove('active-nav'));
        navLinks[index].classList.add('active-nav');
    }

    changeActiveNav();
    window.addEventListener('scroll', changeActiveNav);
});

//Chatbot

document.getElementById('iconChatBot').addEventListener('click', function() {
    const chatBotContent = document.getElementById('chatBotContent');
    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ử.
    //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ử.
});

// Ngăn việc đóng form khi nhấp vào bên trong form
document.getElementById('chatBotContent').addEventListener('click', function(event) {
    event.stopPropagation(); // Ngăn chặn sự kiện click từ lan rộng ra ngoài
});

// Xử lý sự kiện gửi form
document.getElementById('chatBotForm').addEventListener('submit', function(event) {
    event.preventDefault();
    const input = document.getElementById('chatBotInput').value;
    if (input.trim() !== '') {
        const chatBotMid = document.getElementById('chatBotmid');

        const userMessage = document.createElement('div');
        userMessage.style.textAlign = 'right';
        userMessage.style.marginRight = '8px';
        userMessage.style.color = 'black';
        userMessage.textContent = input;
        chatBotMid.appendChild(userMessage);

        fetch('/send-message', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ message: input })
        })
            .then(response => response.json())
            .then(data => {
                const botResponse = document.createElement('div');
                botResponse.style.textAlign = 'left';
                botResponse.style.marginLeft = '8px';
                botResponse.style.color = 'black';
                botResponse.textContent = `Bot response: ${data.response}`;
                chatBotMid.appendChild(botResponse);

                // Scroll to the bottom when a new message is added
                chatBotMid.scrollTop = chatBotMid.scrollHeight;
            });

        document.getElementById('chatBotInput').value = '';
    }
});

// Đóng form khi nhấp ra ngoài
document.addEventListener('click', function(event) {
    const chatBotContent = document.getElementById('chatBotContent');
    if (!chatBotContent.contains(event.target) && !event.target.matches('#iconChatBot')) {
        chatBotContent.style.display = 'none';
    }
});