mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-20 20:46:15 +08:00
updating margin on resize with debounce
This commit is contained in:
parent
5ddf832c02
commit
7da16a77aa
1 changed files with 18 additions and 6 deletions
|
@ -1,5 +1,16 @@
|
|||
import { debounce } from "throttle-debounce";
|
||||
import * as Misc from "../utils/misc";
|
||||
|
||||
function updateMargin(): void {
|
||||
console.log("updating margin");
|
||||
const height = $("#bannerCenter").height() as number;
|
||||
$("#centerContent").css(
|
||||
"padding-top",
|
||||
height + Misc.convertRemToPixels(2) + "px"
|
||||
);
|
||||
$("#notificationCenter").css("margin-top", height + "px");
|
||||
}
|
||||
|
||||
let id = 0;
|
||||
class Notification {
|
||||
id: number;
|
||||
|
@ -152,12 +163,7 @@ class Notification {
|
|||
</div>
|
||||
</div>
|
||||
`);
|
||||
const height = $("#bannerCenter").height() as number;
|
||||
$("#centerContent").css(
|
||||
"padding-top",
|
||||
height + Misc.convertRemToPixels(2) + "px"
|
||||
);
|
||||
$("#notificationCenter").css("margin-top", height + "px");
|
||||
updateMargin();
|
||||
if (this.duration >= 0) {
|
||||
$(`#bannerCenter .banner[id='${this.id}'] .closeButton`).on(
|
||||
"click",
|
||||
|
@ -247,3 +253,9 @@ export function addBanner(
|
|||
).show();
|
||||
// );
|
||||
}
|
||||
|
||||
const debouncedMarginUpdate = debounce(100, updateMargin);
|
||||
|
||||
$(window).on("resize", () => {
|
||||
debouncedMarginUpdate();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue