Add parallax
This commit is contained in:
parent
c8679b77bf
commit
c2dbf995cc
18 changed files with 102 additions and 56 deletions
24
src/page/background/background.ts
Normal file
24
src/page/background/background.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { PageElement } from "../../framework/page-element";
|
||||
import { createElement } from "../../framework/element-factory";
|
||||
import { generate } from "./background.html";
|
||||
|
||||
export class PageBackground extends PageElement {
|
||||
public constructor(
|
||||
private speed: number,
|
||||
count: number,
|
||||
width: number,
|
||||
probability: number,
|
||||
color: string
|
||||
) {
|
||||
super();
|
||||
this.setElement(createElement(generate(count, probability, width, color)));
|
||||
}
|
||||
|
||||
public onAfterLoad(parent: HTMLElement) {
|
||||
window.addEventListener("scroll", () => {
|
||||
this.getElement().style.transform = `translateY(-${window.scrollY *
|
||||
this.speed}px)`;
|
||||
});
|
||||
super.onAfterLoad(parent);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue