Improve video UX
This commit is contained in:
parent
08feeb6bfc
commit
f3c8453782
13 changed files with 101 additions and 69 deletions
|
|
@ -2,15 +2,40 @@ import { PageElement } from '../../page-element';
|
|||
import { createElement } from '../../../helper/create-element';
|
||||
import { generate } from './video.html';
|
||||
import { url } from '../../../types/url';
|
||||
import { ResponsiveImage } from '../../../types/responsive-image';
|
||||
|
||||
export interface VideoParameters {
|
||||
mp4: url;
|
||||
webm: url;
|
||||
poster: ResponsiveImage;
|
||||
invertButton?: boolean;
|
||||
}
|
||||
|
||||
export class Video extends PageElement {
|
||||
public constructor(options: {
|
||||
poster?: url;
|
||||
mp4: url;
|
||||
webm: url;
|
||||
shouldActLikeGif?: boolean;
|
||||
container?: boolean;
|
||||
}) {
|
||||
private video: HTMLVideoElement;
|
||||
|
||||
public constructor(options: VideoParameters) {
|
||||
super(createElement(generate(options)));
|
||||
this.video = this.query('video') as HTMLVideoElement;
|
||||
this.video.addEventListener('click', this.startVideo.bind(this));
|
||||
this.query('.start-button').addEventListener('click', this.startVideo.bind(this));
|
||||
this.video.addEventListener('pause', this.stopVideo.bind(this));
|
||||
}
|
||||
|
||||
private startVideo(e: Event) {
|
||||
if (this.video.paused) {
|
||||
this.query('.start-button').style.visibility = 'hidden';
|
||||
this.video.play();
|
||||
this.video.controls = true;
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private stopVideo(e: Event) {
|
||||
if (this.video.paused) {
|
||||
this.query('.start-button').style.visibility = 'visible';
|
||||
this.video.controls = false;
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue