- add scroll function
This commit is contained in:
Kum1ta
2024-09-17 16:54:22 +02:00
parent 7a49159282
commit a5b2bb95a8
4 changed files with 19 additions and 17 deletions

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* main.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/25 00:02:19 by edbernar #+# #+# */
/* Updated: 2024/09/17 13:06:30 by marvin ### ########.fr */
/* Updated: 2024/09/17 16:43:50 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,7 @@ class HomePage
Login.create();
LiveChat.create();
window.addEventListener('scroll', scrool);
window.addEventListener('bScroll', scrollToSection)
document.getElementById('AAAAAAA').addEventListener('click', scrollToSection)
}
static dispose()
@ -31,13 +31,16 @@ class HomePage
Login.dispose();
LiveChat.dispose();
window.removeEventListener('scroll', scrool);
window.removeEventListener('bScroll', scrollToSection)
document.getElementById('AAAAAAA').removeEventListener('click', scrollToSection)
}
};
function scrollToSection() {
document.querySelector('#homeSection relative').scrollIntoView({
behavior: 'smooth'
function scrollToSection()
{
const pos = document.getElementById('QWERTYUIOP').getBoundingClientRect().top + window.scrollY;
window.scroll({
top: pos,
behavior: 'smooth'
});
console.log("CACA");
}

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/09/17 15:04:18 by edbernar ### ########.fr */
/* Updated: 2024/09/17 15:38:02 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -113,10 +113,12 @@ class MultiOnlineGamePage
renderer.setAnimationLoop(loop)
sendRequest('game', {action: 1});
let lastPosition = player.object.position.x;
let lastUp = player.isUp;
interval = setInterval(() => {
if (player && player.object.position.x != lastPosition)
if (player && player.object.position.x != lastPosition || player.isUp != lastUp)
{
lastPosition = player.object.position.x;
lastUp = player.isUp;
sendRequest('game', {action: 3, pos: player.object.position.x, up: player.isUp});
}
}, 1000 / 20);
@ -160,9 +162,6 @@ class MultiOnlineGamePage
static opponentDisconnect()
{
pageRenderer.changePage('lobbyPage');
setTimeout(() => {
CN.new("Game", "Opponent disconnect", CN.defaultIcon.error);
}, 1000);
}
}