8000 fix(gamemodes): changed offset calculation and added resize support by pedroalves80 · Pull Request #18 · momentum-mod/frontpage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(gamemodes): changed offset calculation and added resize support #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/js/gamemodes.ts
90C7
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ let selected: Gamemode | undefined;
let timerHandle: ReturnType<typeof setTimeout> | undefined;
let timeBar: HTMLDivElement;
let timeBarProgress: HTMLSpanElement;
let buttonHasBeenClicked = false;

//prettier-ignore
function init() {
Expand Down Expand Up @@ -167,9 +168,15 @@ function init() {
},
{ root: null, rootMargin: '0px', threshold: 0 }
).observe(sections);

window.addEventListener('resize', () => {
if (selected) selectMode(selected, !buttonHasBeenClicked);
});
}

function selectMode(gamemode: Gamemode, autoswitch: boolean) {
buttonHasBeenClicked = !autoswitch;

if (selected) {
selected.button?.classList?.remove('selected');
selected.section?.classList?.remove('selected');
Expand All @@ -181,8 +188,17 @@ function selectMode(gamemode: Gamemode, autoswitch: boolean) {
timerHandle = undefined;
}

timeBar.style.width = `${parseFloat(window.getComputedStyle(gamemode.button).width.replace('px', ''))}px`;
timeBar.style.left = `${gamemode.button.offsetLeft}px`;
const selection = document.querySelector('#GamemodeSelection');
const selectionRect = selection.getBoundingClientRect();
const buttonRect = gamemode.button.getBoundingClientRect();
const scrollOffset = selection.scrollLeft; // Horizontal scroll position
const leftPosition = buttonRect.left - selectionRect.left + scrollOffset;

timeBar.style.left = `${leftPosition}px`;
timeBar.style.width = `${buttonRect.width}px`;

timeBar.style.left = `${leftPosition}px`;
timeBar.style.width = `${buttonRect.width}px`;
timeBarProgress.style.width = '0%';
timeBarProgress.style.transitionDuration = '0s';

Expand Down
0