Skip to content

Commit

Permalink
Add an aspectratio attribute
Browse files Browse the repository at this point in the history
Makes it possible to handle non-16/9 videos, and fixes justinribeiro#92.
  • Loading branch information
elibarzilay committed Jul 28, 2023
1 parent 50c254b commit 2271641
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lite-youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class LiteYTEmbed extends HTMLElement {
this.setAttribute('playlistid', id);
}

get aspectRatio(): string {
return this.getAttribute('aspectratio') ?? '';
}

set aspectRatio(title: string) {
this.setAttribute('aspectratio', title);
}

get videoTitle(): string {
return this.getAttribute('videotitle') || 'Video';
}
Expand Down Expand Up @@ -122,12 +130,12 @@ export class LiteYTEmbed extends HTMLElement {
display: block;
position: relative;
width: 100%;
padding-bottom: calc(100% / (16 / 9));
padding-bottom: calc(100% / (${this.aspectRatio || '16 / 9'}));
}
@media (max-width: 40em) {
:host([short]) {
padding-bottom: calc(100% / (9 / 16));
padding-bottom: calc(100% / (${this.aspectRatio || '9 / 16'}));
}
}
Expand Down

0 comments on commit 2271641

Please # to comment.