How to hide the \"more videos\" section in Youtube iframes, when the user stops the video?
Example:
Reduced test case here: https://codepen.io/jesserosenfield/full/VwZELye
Basically–– delay the pause and play functions using a custom button using setTimeout
... add showing/pausing/playing/paused classes to control CSS transitions of a "placeholder image".
Happy to explain in more detail if you need it, but the code pen should be pretty self explanatory!
Javascript:
var player,
$player,
$playerWrap,
$playerParent;
// 3. This function creates an
HTML
CSS (LESS)
.player-ph{
width: 50%;
height: 100%;
position: relative;
background: url(https://images.unsplash.com/photo-1503714964235-8954a5249c00?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80);
background-size: cover;
mix-blend-mode: multiply;
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */;
}
#player-wrap {
cursor: pointer;
width: 100%;
padding-bottom: 56.25%;
position: relative;
}
.player-ph,
.player-ph--color,
#player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#player {
z-index: 5;
pointer-events: none;
opacity: 0
}
.player-ph--color {
background: red;
}
.player-ph--color:after {
content: "▶️";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 300px;
font-size: 150px;
color: #fff;
opacity: .5;
display: block;
z-index: 2
}
#player {
transition: opacity .325s ease-out;
}
.player-ph--color:after {
transition: opacity 1s ease-out;
}
#player-parent {
&.pausing,
&.paused {
#player {
opacity: 0
}
}
&.playing,
&.showing {
.player-ph--color:after {
opacity: 0
}
}
&.playing #player {
opacity: 1
}
}