Skip to content

Commit 390a245

Browse files
committed
Fix player size in mobile
1 parent 73f3d71 commit 390a245

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

scripts.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@ function getVideoIdFromURL(url) {
1919
}
2020

2121
function onYouTubeIframeAPIReady() {
22+
const screenWidth = window.innerWidth;
23+
let playerWidth, playerHeight;
24+
25+
if (screenWidth >= 1200) {
26+
playerWidth = 640;
27+
playerHeight = 360;
28+
} else if (screenWidth >= 768) {
29+
playerWidth = 480;
30+
playerHeight = 270;
31+
} else {
32+
playerWidth = 320;
33+
playerHeight = 180;
34+
}
35+
2236
player = new YT.Player('player', {
23-
height: '360',
24-
width: '640',
37+
height: playerHeight.toString(),
38+
width: playerWidth.toString(),
2539
events: {
2640
'onReady': onPlayerReady,
2741
'onStateChange': onPlayerStateChange

0 commit comments

Comments
 (0)