Left side of image disappears - javascript

After clicking on the play image, the left side of it disappears, and is not visible.
How do I get the left side of the play image to stay visible and not disappear?
I don't understand why this is happening.
How is this issue resolved?
That is everything about the problem I am having.
code https://jsfiddle.net/kqr691fs/
(function iife() {
"use strict";
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
const thewrap = curtain.parentElement.querySelector(".container");
show(thewrap);
}
const cover = document.querySelector(".jacketa");
cover.addEventListener("click", coverClickHandler);
}());
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #353198;
}
.curtain {
position: relative;
width: 100%;
height: 100%;
}
.curtain.slide {
height: auto;
min-height: 100%;
overflow: hidden;
}
.panel-left,
.panel-right {
position: absolute;
height: 100%;
width: 50%;
top: 0%;
transition: all ease 10s;
/*background-image: url("https://picsum.photos/600");
background-size: cover;
background-repeat: no-repeat;
background-position: center;*/
overflow: hidden;
}
.panel-left {
left: 0;
/*background-color: rgb(91, 96, 106);*/
}
.panel-right {
right: 0;
/*background-color: rgb(229, 211, 211);*/
}
.panel-left::before,
.panel-right::before {
content: "";
position: absolute;
height: 100%;
width: 200%;
top: 0;
left: 0;
background-image: url("https://picsum.photos/1920/1080");
background-size: auto;
background-repeat: no-repeat;
background-position: 0 0;
}
.panel-right::before {
left: -100%;
}
.curtain.slide .panel-left {
transform: translateX(-100%);
}
.curtain.slide .panel-right {
transform: translateX(100%);
}
.outer {
display: table;
height: 100%;
margin: 0 auto;
}
.tcell {
display: table-cell;
vertical-align: middle;
}
.jacketa {
position: absolute;
top: 40px;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
}
.j1 .jacketa {
left: 30px;
}
.j2 .jacketa {
right: 30px;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 240px;
height: 260px;
margin: auto;
border-radius: 50%;
transition: 10s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.container {
height: auto;
}
.curtain.slide .j1 {
left: -500%;
}
.curtain.slide .j2 {
left: 500%;
}
.hide {
display: none;
}
<div class="curtain">
<div class="outer">
<div class="tcell">
<div class="container hide">
<div class="container-top">
</div>
</div>
<div class="panel-left"> </div>
<div class="panel-right"> </div>
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>
</div>
</div>

'Click' event is working only on the left side image. Because, here querySelector() is used. It will return an Element object representing the first element in the document that matches the specified set of CSS selectors, or null is returned if there are no matches.
Instead you can use querySelectorAll() like this
using ES6:
const cover = document.querySelectorAll('.jacketa');
cover.forEach(el => el.addEventListener('click', coverClickHandler));
using For Loop:
const cover = document.querySelectorAll('.jacketa');
for (var i = 0; i < cover.length; i++) {
cover[i].addEventListener('click', coverClickHandler);
}
Now both sides of the image will trigger the event.

I marked the modifications I made, there are 2 css classes modified plus the js code in the coverClickHandler method
(function iife() {
"use strict";
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
//Modified
function coverClickHandler() {
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
const thewrap = curtain.parentElement.querySelector(".container");
show(thewrap);
}
const cover = document.querySelector(".jacketa");
cover.addEventListener("click", coverClickHandler);
}());
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #353198;
}
.curtain {
position: relative;
width: 100%;
height: 100%;
}
.curtain.slide {
height: auto;
min-height: 100%;
overflow: hidden;
}
.panel-left,
.panel-right {
position: absolute;
height: 100%;
width: 50%;
top: 0%;
transition: all ease 10s;
/*background-image: url("https://picsum.photos/600");
background-size: cover;
background-repeat: no-repeat;
background-position: center;*/
overflow: hidden;
}
.panel-left {
left: 0;
/*background-color: rgb(91, 96, 106);*/
}
.panel-right {
right: 0;
/*background-color: rgb(229, 211, 211);*/
}
.panel-left::before,
.panel-right::before {
content: "";
position: absolute;
height: 100%;
width: 200%;
top: 0;
left: 0;
background-image: url("https://picsum.photos/1920/1080");
background-size: auto;
background-repeat: no-repeat;
background-position: 0 0;
}
.panel-right::before {
left: -100%;
}
.curtain.slide .panel-left {
transform: translateX(-100%);
}
.curtain.slide .panel-right {
transform: translateX(100%);
}
.outer {
display: table;
height: 100%;
margin: 0 auto;
}
.tcell {
display: table-cell;
vertical-align: middle;
}
.jacketa {
position: absolute;
top: 40px;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
}
.j1 .jacketa {
left: 30px;
}
.j2 .jacketa {
right: 30px;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 240px;
height: 260px;
margin: auto;
border-radius: 50%;
transition: 10s ease;
}
/*Modified*/
.j1 {
position: absolute;
right: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.container {
height: auto;
}
/*Modified*/
.curtain.slide .j1 {
right: 500%;
}
.curtain.slide .j2 {
left: 500%;
}
.hide {
display: none;
}
<div class="curtain">
<div class="outer">
<div class="tcell">
<div class="container hide">
<div class="container-top">
</div>
</div>
<div class="panel-left"> </div>
<div class="panel-right"> </div>
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>
</div>
</div>

Related

How to slide door down on page load, then slide door up on button click

When the webpage loads in, the door goes down, and when the button is pressed, the door should go back up.
The fan and the background should first be seen, then the door should slide down, then clicking on the door raises it.
Is there a way for this to be improved?
code https://jsfiddle.net/jt9vpeyx/
.video-one {
top: -101%;
transition: all 10s ease-in 0s;
transition-delay: 1s;
}
.video-one.slide {
top: 0%;
}
.curtain.slide .video-one {
transition-delay: 3s;
transform: translateY(calc(-100% - 1px));
}
let videoOne = document.querySelector('.video-one')
requestAnimationFrame(() => {
videoOne.classList.add("slide");
})
How the code works is, on page load the wall comes down, then on button click the wall goes up.
let videoOne = document.querySelector('.video-one')
requestAnimationFrame(() => {
videoOne.classList.add("slide");
})
const manageCover = (function makeManageCover() {
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function openCurtain(cover) {
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
return curtain;
}
function showVideo(curtain) {
const thewrap = curtain.parentElement.querySelector(".wrap");
show(thewrap);
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
const curtain = openCurtain(cover);
showVideo(curtain);
cover.dispatchEvent(new Event("afterClick"));
}
function init(callback) {
const cover = document.querySelector(".play");
cover.addEventListener("click", coverClickHandler);
cover.addEventListener("afterClick", callback);
}
return {
init
};
}());
const videoPlayer = (function makeVideoPlayer() {
let playlist;
let player;
function loadIframeScript() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
const cover = document.querySelector(".play");
const wrapper = cover.parentElement;
const frameContainer = wrapper.querySelector(".video");
addPlayer(frameContainer, playlist);
}
function shufflePlaylist(player) {
player.setShuffle(true);
player.playVideoAt(0);
player.stopVideo();
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
shufflePlaylist(player);
}
function createPlaylist(videoIds) {
return videoIds.join();
}
function createOptions(videoIds) {
const options = {
height: 360,
host: "https://www.youtube-nocookie.com",
width: 640
};
options.playerVars = {
autoplay: 0,
cc_load_policy: 0,
controls: 1,
disablekb: 1,
fs: 0,
iv_load_policy: 3,
rel: 0
};
options.events = {
"onReady": onPlayerReady
};
options.playerVars.loop = 1;
options.playerVars.playlist = createPlaylist(videoIds);
return options;
}
function createVideoOptions(ids) {
const options = createOptions(ids);
return options;
}
function addPlayer(video, ids) {
const options = createVideoOptions(ids);
player = new YT.Player(video, options);
return player;
}
function play() {
if (player && player.playVideo) {
player.playVideo();
}
}
function init(videoIds) {
player = null;
loadIframeScript();
window.onYouTubeIframeAPIReady = onYouTubeIframeAPIReady;
playlist = videoIds;
return play;
}
return {
init,
play
};
}());
manageCover.init(videoPlayer.init([
"0dgNc5S8cLI",
]));
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-image: repeating-linear-gradient(135deg, rgb(0, 0, 0) 0px, rgb(0, 0, 0) 10px, transparent 10px, transparent 11px), repeating-linear-gradient(22.5deg, rgb(0, 0, 0) 0px, rgb(0, 0, 0) 10px, transparent 10px, transparent 11px), linear-gradient(90deg, rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221));
}
.container {
position: absolute;
left: 0;
right: 0;
min-height: 100%;
min-width: 255px;
display: flex;
padding: 8px 8px;
}
.curtain {
flex: 1 0 0;
margin: auto;
max-width: 640px;
border: 21px solid;
border-radius: 3.2px;
border-color: #000 #101010 #000 #101010;
position: relative;
}
.curtain::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: #0a0a0a;
border: 1px solid;
border-color: #000 #101010 #000 #101010;
;
}
.curtain::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
outline: 1px solid #f91f6e;
pointer-events: none;
}
.curtain.slide::after {
outline: 1px solid #0059dd;
transition: outline 2s ease-in;
/* add this */
/*background-image: none;*/
}
:root {
--wide: 32px;
--angle1: 0;
--angle2: -90;
}
.video-one {
position: absolute;
height: 100%;
width: 100%;
top: 0;
background: repeating-linear-gradient( calc(var(--angle1) * 1deg), #ffffff00 0, #ffffff00 var(--wide), #ffffff1a calc(var(--wide) + 1px), #0000004d calc(var(--wide) + 2px), #ffffff00 calc(var(--wide) + 5px)), repeating-linear-gradient( calc(calc(var(--angle2) + 90) * 1deg), #ffffff00 0, #ffffff00 var(--wide), #ffffff1a calc(var(--wide) + 1px), #0000004d calc(var(--wide) + 2px), #ffffff00 calc(var(--wide) + 5px));
background-color: #222;
border-bottom: 2px solid red;
background-repeat: no-repeat;
z-index: 0;
}
.video-one::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: url("https://via.placeholder.com/264x264");
background-position: center;
background-size: 41.25% 73.33%;
background-repeat: no-repeat;
}
.ratio-keeper {
position: relative;
height: 0;
padding-top: 56.25%;
margin: auto;
overflow: hidden;
}
.fence {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
background: linear-gradient(45deg, transparent, transparent 7px, rgb(113, 121, 126) 7px, rgb(113, 121, 126) 7.5px, transparent 7.5px, transparent 10px), linear-gradient(-45deg, transparent, transparent 7px, rgb(113, 121, 126) 7px, rgb(113, 121, 126) 7.5px, transparent 7.5px, transparent 10px);
background-size: 10px 10px;
filter: drop-shadow(0 0 5px #000);
clip-path: circle(25% at center);
}
.fence>div {
position: absolute;
/*top: 0;*/
left: 0;
right: 0;
/*width: 100%;*/
height: 0.55%;
/*height: 2px;*/
background: green;
}
.fence>div:nth-child(1) {
top: 10%;
}
.fence>div:nth-child(2) {
top: 20%;
}
.fence>div:nth-child(3) {
top: 30%;
}
.fence>div:nth-child(4) {
top: 40%;
}
.fence>div:nth-child(5) {
top: 50%;
}
.fence>div:nth-child(6) {
top: 60%;
}
.fence>div:nth-child(7) {
top: 70%;
}
.fence>div:nth-child(8) {
top: 80%;
}
.fence>div:nth-child(9) {
top: 90%;
}
.fan svg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 70%;
height: 70%;
margin: auto;
}
.slide .fan svg {
animation: fan-spin linear;
animation-duration: 12s;
animation-iteration-count: 1;
animation-delay: 3s;
}
#keyframes fan-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.video-frame {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
iframe {
display: block;
animation: iframe 6s ease forwards;
animation-delay: 6s;
opacity: 0;
}
#keyframes iframe {
to {
opacity: 1;
}
}
iframe {
user-select: none;
}
.play {
-webkit-appearance: none;
appearance: none;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
width: 90px;
height: 90px;
border-radius: 50%;
cursor: pointer;
border: 9px solid;
z-index: 1;
background: transparent;
filter: drop-shadow(3px 3px 3px #000000b3);
border-color: blue;
animation: fadeInPlay 2s ease-in 2s forwards;
animation-delay: 10s;
opacity: 0;
cursor: default;
pointer-events:none;
}
#keyframes fadeInPlay {
0% {
opacity: 0;
}
99.9% {
opacity: 1;
pointer-events:none;
}
100% {
opacity: 1;
cursor: pointer;
pointer-events:initial;
}
}
.play::before {
content: "";
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 27px solid;
transform: translateX(4px);
border-left-color: blue;
}
.play:hover {
box-shadow: 0 0 0 5px rgba(20, 179, 33, 0.5);
}
.play:focus {
outline: 0;
box-shadow: 0 0 0 5px rgba(111, 0, 255, 0.5);
}
.exit {
position: absolute;
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47px;
height: 47px;
cursor: pointer;
border-radius: 100%;
background: transparent;
border: 5px solid red;
box-sizing: border-box;
opacity: 0;
pointer-events: none;
clip-path: circle(50%);
}
.slide .exit {
animation: fadeInExit 4s forwards 7.5s;
}
#keyframes fadeInExit {
99% {
pointer-events: none;
}
100% {
pointer-events: initial;
opacity: 1;
}
}
.exit::before,
.exit::after {
content: "";
background-color: red;
width: 47px;
height: 5px;
position: absolute;
top: 0px;
left: -5px;
right: 0;
bottom: 0;
margin: auto;
}
.exit::before {
transform: rotate(45deg);
}
.exit::after {
transform: rotate(-45deg);
}
.hide {
display: none;
}
.video-one {
top: -101%;
transition: all 10s ease-in 0s;
transition-delay: 1s;
}
.video-one.slide {
top: 0%;
}
.curtain.slide .video-one {
transition-delay: 3s;
transform: translateY(calc(-100% - 1px));
}
<div class="container">
<div class="curtain">
<div class="ratio-keeper">
<div class="fence">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="fan">
<svg width="70%" height="70%" viewBox="76 130 381 381">
<g id="fan">
<path fill="#000" stroke="#000"
d="m166.3352 168.6294c5.5396 2.4448 45.2339 54.394 72.7499 91.0151-9.1901-44.8757-21.7959-109.0279-19.9558-114.796 4.1462-12.9949 33.7039-13.5172 41.5845-13.7579 7.8827-.2415 37.4165-1.5221 42.3488 11.1948 2.1872 5.6436-6.4773 70.4506-12.9142 115.8007 25.2309-38.2323 61.6818-92.5089 67.0612-95.2865 12.119-6.2568 33.3898 14.2749 39.1337 19.6768 5.7424 5.402 27.5341 25.3815 22.0294 37.859-2.4441 5.5389-54.3954 45.2354-91.0172 72.7506 44.8757-9.1901 109.0293-21.7959 114.7974-19.9559 12.9927 4.1442 13.5193 33.7032 13.7586 41.5838.2422 7.8819 1.5221 37.4165-11.192 42.3473-5.6471 2.1894-70.4541-6.4765-115.8049-12.9127 38.2323 25.2323 92.5081 61.6783 95.2871 67.0605 6.2581 12.1175-14.2742 33.3877-19.6776 39.133-5.4027 5.7432-25.3815 27.5341-37.8563 22.0279-5.5396-2.4434-45.2361-54.3961-72.7534-91.0143 9.1901 44.8757 21.7952 109.0287 19.9551 114.7953-4.1434 12.9934-33.7026 13.5157-41.5852 13.7586-7.8799.24-37.4165 1.5221-42.3431-11.1936-2.1887-5.6464 6.4779-70.4541 12.9133-115.8071-25.2323 38.2323-61.6824 92.5124-67.0639 95.2908-12.1169 6.256-33.3891-14.2728-39.1337-19.6754-5.7432-5.4027-27.5313-25.383-22.0251-37.8578 2.4434-5.5396 54.394-45.2339 91.0136-72.7526-44.8764 9.1908-109.0266 21.7944-114.7967 19.9566-12.9934-4.1434-13.5171-33.7025-13.7586-41.5852-.2407-7.8806-1.5221-37.4165 11.1963-42.346 5.6443-2.1879 70.4498 6.4752 115.8 12.9121-38.233-25.2316-92.5081-61.6783-95.2865-67.0612-6.256-12.1169 14.2748-33.3913 19.6768-39.1337 5.4006-5.7438 25.3794-27.5333 37.8584-22.0272z" />
</g>
</svg>
</div>
<div class="cross"></div>
<div class="wrap hide">
<div class="video video-frame" data-id=""></div>
</div>
<div class="video-one"></div>
</div>
<a href="https://www.google.com/">
<div class="exit"></div>
</a>
</div>
<button class="play" type="button" aria-label="Open"></button>
</div>
code: https://jsfiddle.net/rn5p9fb4/
What was used:
.video-one {
top: 0;
transform: translateY(calc(-100% - 1px));
animation: curtainDown 10s ease-in 1s forwards;
}
#keyframes curtainDown {
to {
transform: translateY(0%);
}
}
.curtain.slide .video-one {
transform: translateY(0%);
animation: curtainUp 8s ease-in 3s forwards;
}
#keyframes curtainUp {
to {
transform: translateY(calc(-100% - 1px));
}
}
const manageCover = (function makeManageCover() {
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function openCurtain(cover) {
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
//curtain.classList.add("slide2");
return curtain;
}
function showVideo(curtain) {
const thewrap = curtain.parentElement.querySelector(".wrap");
show(thewrap);
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
const curtain = openCurtain(cover);
// videoOne.classList.add("slide");
showVideo(curtain);
cover.dispatchEvent(new Event("afterClick"));
}
function init(callback) {
const cover = document.querySelector(".play");
cover.addEventListener("click", coverClickHandler);
cover.addEventListener("afterClick", callback);
}
return {
init
};
}());
const videoPlayer = (function makeVideoPlayer() {
let playlist;
let player;
function loadIframeScript() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
const cover = document.querySelector(".play");
const wrapper = cover.parentElement;
const frameContainer = wrapper.querySelector(".video");
addPlayer(frameContainer, playlist);
}
function shufflePlaylist(player) {
player.setShuffle(true);
player.playVideoAt(0);
player.stopVideo();
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
shufflePlaylist(player);
}
function createPlaylist(videoIds) {
return videoIds.join();
}
function createOptions(videoIds) {
const options = {
height: 360,
host: "https://www.youtube-nocookie.com",
width: 640
};
options.playerVars = {
autoplay: 0,
cc_load_policy: 0,
controls: 1,
disablekb: 1,
fs: 0,
iv_load_policy: 3,
rel: 0
};
options.events = {
"onReady": onPlayerReady
};
options.playerVars.loop = 1;
options.playerVars.playlist = createPlaylist(videoIds);
return options;
}
function createVideoOptions(ids) {
const options = createOptions(ids);
return options;
}
function addPlayer(video, ids) {
const options = createVideoOptions(ids);
player = new YT.Player(video, options);
return player;
}
function play() {
if (player && player.playVideo) {
player.playVideo();
}
}
function init(videoIds) {
player = null;
loadIframeScript();
window.onYouTubeIframeAPIReady = onYouTubeIframeAPIReady;
playlist = videoIds;
return play;
}
return {
init,
play
};
}());
manageCover.init(videoPlayer.init([
"0dgNc5S8cLI",
]));
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-image: repeating-linear-gradient(135deg, rgb(0, 0, 0) 0px, rgb(0, 0, 0) 10px, transparent 10px, transparent 11px), repeating-linear-gradient(22.5deg, rgb(0, 0, 0) 0px, rgb(0, 0, 0) 10px, transparent 10px, transparent 11px), linear-gradient(90deg, rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221));
}
.container {
position: absolute;
left: 0;
right: 0;
min-height: 100%;
min-width: 255px;
display: flex;
padding: 8px 8px;
}
.curtain {
flex: 1 0 0;
margin: auto;
max-width: 640px;
border: 21px solid;
border-radius: 3.2px;
border-color: #000 #101010 #000 #101010;
position: relative;
}
.curtain::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: #0a0a0a;
border: 1px solid;
border-color: #000 #101010 #000 #101010;
;
}
.curtain::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
outline: 1px solid #f91f6e;
pointer-events: none;
}
.curtain.slide::after {
outline: 1px solid #0059dd;
transition: outline 2s ease-in;
/* add this */
/*background-image: none;*/
}
:root {
--wide: 32px;
--angle1: 0;
--angle2: -90;
}
.video-one {
position: absolute;
height: 100%;
width: 100%;
top: 0;
background: repeating-linear-gradient(calc(var(--angle1) * 1deg), #ffffff00 0, #ffffff00 var(--wide), #ffffff1a calc(var(--wide) + 1px), #0000004d calc(var(--wide) + 2px), #ffffff00 calc(var(--wide) + 5px)), repeating-linear-gradient(calc(calc(var(--angle2) + 90) * 1deg), #ffffff00 0, #ffffff00 var(--wide), #ffffff1a calc(var(--wide) + 1px), #0000004d calc(var(--wide) + 2px), #ffffff00 calc(var(--wide) + 5px));
background-color: #222;
border-bottom: 2px solid red;
background-repeat: no-repeat;
z-index: 0;
}
.video-one::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: url("https://via.placeholder.com/264x264");
background-position: center;
background-size: 41.25% 73.33%;
background-repeat: no-repeat;
}
.ratio-keeper {
position: relative;
height: 0;
padding-top: 56.25%;
margin: auto;
overflow: hidden;
}
.fence {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
background: linear-gradient(45deg, transparent, transparent 7px, rgb(113, 121, 126) 7px, rgb(113, 121, 126) 7.5px, transparent 7.5px, transparent 10px), linear-gradient(-45deg, transparent, transparent 7px, rgb(113, 121, 126) 7px, rgb(113, 121, 126) 7.5px, transparent 7.5px, transparent 10px);
background-size: 10px 10px;
filter: drop-shadow(0 0 5px #000);
clip-path: circle(25% at center);
}
.fence>div {
position: absolute;
/*top: 0;*/
left: 0;
right: 0;
/*width: 100%;*/
height: 0.55%;
/*height: 2px;*/
background: green;
}
.fence>div:nth-child(1) {
top: 10%;
}
.fence>div:nth-child(2) {
top: 20%;
}
.fence>div:nth-child(3) {
top: 30%;
}
.fence>div:nth-child(4) {
top: 40%;
}
.fence>div:nth-child(5) {
top: 50%;
}
.fence>div:nth-child(6) {
top: 60%;
}
.fence>div:nth-child(7) {
top: 70%;
}
.fence>div:nth-child(8) {
top: 80%;
}
.fence>div:nth-child(9) {
top: 90%;
}
.fan svg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 70%;
height: 70%;
margin: auto;
}
.slide .fan svg {
animation: fan-spin linear;
animation-duration: 12s;
animation-iteration-count: 1;
animation-delay: 3s;
}
#keyframes fan-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.video-frame {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
iframe {
display: block;
animation: iframe 6s ease forwards;
animation-delay: 6s;
opacity: 0;
}
#keyframes iframe {
to {
opacity: 1;
}
}
iframe {
user-select: none;
}
.play {
-webkit-appearance: none;
appearance: none;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
width: 90px;
height: 90px;
border-radius: 50%;
cursor: pointer;
border: 9px solid;
z-index: 1;
background: transparent;
filter: drop-shadow(3px 3px 3px #000000b3);
border-color: blue;
animation: fadeInPlay 2s ease-in 2s forwards;
animation-delay: 10s;
opacity: 0;
cursor: default;
pointer-events: none;
}
#keyframes fadeInPlay {
0% {
opacity: 0;
}
99.9% {
opacity: 1;
pointer-events: none;
}
100% {
opacity: 1;
cursor: pointer;
pointer-events: initial;
}
}
.play::before {
content: "";
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 27px solid;
transform: translateX(4px);
border-left-color: blue;
}
.play:hover {
box-shadow: 0 0 0 5px rgba(20, 179, 33, 0.5);
}
.play:focus {
outline: 0;
box-shadow: 0 0 0 5px rgba(111, 0, 255, 0.5);
}
.exit {
position: absolute;
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47px;
height: 47px;
cursor: pointer;
border-radius: 100%;
background: transparent;
border: 5px solid red;
box-sizing: border-box;
opacity: 0;
pointer-events: none;
clip-path: circle(50%);
}
.slide .exit {
animation: fadeInExit 4s forwards 7.5s;
}
#keyframes fadeInExit {
99% {
pointer-events: none;
}
100% {
pointer-events: initial;
opacity: 1;
}
}
.exit::before,
.exit::after {
content: "";
background-color: red;
width: 47px;
height: 5px;
position: absolute;
top: 0px;
left: -5px;
right: 0;
bottom: 0;
margin: auto;
}
.exit::before {
transform: rotate(45deg);
}
.exit::after {
transform: rotate(-45deg);
}
.hide {
display: none;
}
.video-one {
top: 0;
transform: translateY(calc(-100% - 1px));
animation: curtainDown 10s ease-in 1s forwards;
}
#keyframes curtainDown {
to {
transform: translateY(0%);
}
}
.curtain.slide .video-one {
transform: translateY(0%);
animation: curtainUp 8s ease-in 3s forwards;
}
#keyframes curtainUp {
to {
transform: translateY(calc(-100% - 1px));
}
}
<div class="container">
<div class="curtain">
<div class="ratio-keeper">
<div class="fence">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="fan">
<svg width="70%" height="70%" viewBox="76 130 381 381">
<g id="fan">
<path fill="#000" stroke="#000"
d="m166.3352 168.6294c5.5396 2.4448 45.2339 54.394 72.7499 91.0151-9.1901-44.8757-21.7959-109.0279-19.9558-114.796 4.1462-12.9949 33.7039-13.5172 41.5845-13.7579 7.8827-.2415 37.4165-1.5221 42.3488 11.1948 2.1872 5.6436-6.4773 70.4506-12.9142 115.8007 25.2309-38.2323 61.6818-92.5089 67.0612-95.2865 12.119-6.2568 33.3898 14.2749 39.1337 19.6768 5.7424 5.402 27.5341 25.3815 22.0294 37.859-2.4441 5.5389-54.3954 45.2354-91.0172 72.7506 44.8757-9.1901 109.0293-21.7959 114.7974-19.9559 12.9927 4.1442 13.5193 33.7032 13.7586 41.5838.2422 7.8819 1.5221 37.4165-11.192 42.3473-5.6471 2.1894-70.4541-6.4765-115.8049-12.9127 38.2323 25.2323 92.5081 61.6783 95.2871 67.0605 6.2581 12.1175-14.2742 33.3877-19.6776 39.133-5.4027 5.7432-25.3815 27.5341-37.8563 22.0279-5.5396-2.4434-45.2361-54.3961-72.7534-91.0143 9.1901 44.8757 21.7952 109.0287 19.9551 114.7953-4.1434 12.9934-33.7026 13.5157-41.5852 13.7586-7.8799.24-37.4165 1.5221-42.3431-11.1936-2.1887-5.6464 6.4779-70.4541 12.9133-115.8071-25.2323 38.2323-61.6824 92.5124-67.0639 95.2908-12.1169 6.256-33.3891-14.2728-39.1337-19.6754-5.7432-5.4027-27.5313-25.383-22.0251-37.8578 2.4434-5.5396 54.394-45.2339 91.0136-72.7526-44.8764 9.1908-109.0266 21.7944-114.7967 19.9566-12.9934-4.1434-13.5171-33.7025-13.7586-41.5852-.2407-7.8806-1.5221-37.4165 11.1963-42.346 5.6443-2.1879 70.4498 6.4752 115.8 12.9121-38.233-25.2316-92.5081-61.6783-95.2865-67.0612-6.256-12.1169 14.2748-33.3913 19.6768-39.1337 5.4006-5.7438 25.3794-27.5333 37.8584-22.0272z" />
</g>
</svg>
</div>
<div class="cross"></div>
<div class="wrap hide">
<div class="video video-frame" data-id=""></div>
</div>
<div class="video-one"></div>
</div>
<a href="https://www.google.com/">
<div class="exit"></div>
</a>
</div>
<button class="play" type="button" aria-label="Open"></button>
</div>
Transitions work perfectly if you add a frame before it start.
.video-one {
top: -101%;
}
.video-one.closed {
top: 0%;
}
let v1 = document.querySelector('.video-one')
requestAnimationFrame(() => {
// should be a frame while it's not closed for transition to work
videoOne.classList.toggle('closed', true)
})
document.querySelector(".play").onclick = () => {
// for testing: toggle both directions, you may click it many times
videoOne.classList.toggle('closed', /* false */ )
// for usage: toggle false or classList.remove
// v1.classList.toggle('closed', false)
}
let videoOne = document.querySelector('.video-one')
requestAnimationFrame(() => {
// should be a frame while it's not closed for transition to work
videoOne.classList.toggle('closed', true)
})
const manageCover = (function makeManageCover() {
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function openCurtain(cover) {
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
return curtain;
}
function showVideo(curtain) {
const thewrap = curtain.parentElement.querySelector(".wrap");
show(thewrap);
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
const curtain = openCurtain(cover);
videoOne.classList.toggle('closed', false )
showVideo(curtain);
cover.dispatchEvent(new Event("afterClick"));
}
function init(callback) {
const cover = document.querySelector(".play");
cover.addEventListener("click", coverClickHandler);
cover.addEventListener("afterClick", callback);
}
return {
init
};
}());
const videoPlayer = (function makeVideoPlayer() {
let playlist;
let player;
function loadIframeScript() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
const cover = document.querySelector(".play");
const wrapper = cover.parentElement;
const frameContainer = wrapper.querySelector(".video");
addPlayer(frameContainer, playlist);
}
function shufflePlaylist(player) {
player.setShuffle(true);
player.playVideoAt(0);
player.stopVideo();
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
shufflePlaylist(player);
}
function createPlaylist(videoIds) {
return videoIds.join();
}
function createOptions(videoIds) {
const options = {
height: 360,
host: "https://www.youtube-nocookie.com",
width: 640
};
options.playerVars = {
autoplay: 0,
cc_load_policy: 0,
controls: 1,
disablekb: 1,
fs: 0,
iv_load_policy: 3,
rel: 0
};
options.events = {
"onReady": onPlayerReady
};
options.playerVars.loop = 1;
options.playerVars.playlist = createPlaylist(videoIds);
return options;
}
function createVideoOptions(ids) {
const options = createOptions(ids);
return options;
}
function addPlayer(video, ids) {
const options = createVideoOptions(ids);
player = new YT.Player(video, options);
return player;
}
function play() {
if (player && player.playVideo) {
player.playVideo();
}
}
function init(videoIds) {
player = null;
loadIframeScript();
window.onYouTubeIframeAPIReady = onYouTubeIframeAPIReady;
playlist = videoIds;
return play;
}
return {
init,
play
};
}());
manageCover.init(videoPlayer.init([
"",
]));
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background-image: repeating-linear-gradient(135deg, rgb(0, 0, 0) 0px, rgb(0, 0, 0) 10px, transparent 10px, transparent 11px), repeating-linear-gradient(22.5deg, rgb(0, 0, 0) 0px, rgb(0, 0, 0) 10px, transparent 10px, transparent 11px), linear-gradient(90deg, rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221), rgb(0, 89, 221));
}
.container {
position: absolute;
left: 0;
right: 0;
min-height: 100%;
min-width: 255px;
display: flex;
padding: 8px 8px;
}
.curtain {
flex: 1 0 0;
margin: auto;
max-width: 640px;
border: 21px solid;
border-radius: 3.2px;
border-color: #000 #101010 #000 #101010;
position: relative;
}
.curtain::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: #0a0a0a;
border: 1px solid;
border-color: #000 #101010 #000 #101010;
;
}
.curtain::after {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
outline: 1px solid #f91f6e;
pointer-events: none;
}
.curtain.slide::after {
outline: 1px solid #0059dd;
transition: outline 2s ease-in;
/* add this */
/*background-image: none;*/
}
:root {
--wide: 32px;
--angle1: 0;
--angle2: -90;
}
.video-one {
position: absolute;
height: 100%;
width: 100%;
top: 0;
transition: all 8s ease-in 0s;
transition-delay: 1s;
background: repeating-linear-gradient( calc(var(--angle1) * 1deg), #ffffff00 0, #ffffff00 var(--wide), #ffffff1a calc(var(--wide) + 1px), #0000004d calc(var(--wide) + 2px), #ffffff00 calc(var(--wide) + 5px)), repeating-linear-gradient( calc(calc(var(--angle2) + 90) * 1deg), #ffffff00 0, #ffffff00 var(--wide), #ffffff1a calc(var(--wide) + 1px), #0000004d calc(var(--wide) + 2px), #ffffff00 calc(var(--wide) + 5px));
background-color: #222;
border-bottom: 2px solid red;
background-repeat: no-repeat;
z-index: 0;
x-animation: slidedown 8s forwards;
}
#keyframes slidedown {
to {
transform: translateY(calc(+100% + 1px));
}
}
.curtain.slide .video-one {
transform: translateY(calc(-100% - 1px));
}
.ratio-keeper {
position: relative;
height: 0;
padding-top: 56.25%;
margin: auto;
overflow: hidden;
}
.fence {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
background: linear-gradient(45deg, transparent, transparent 7px, rgb(113, 121, 126) 7px, rgb(113, 121, 126) 7.5px, transparent 7.5px, transparent 10px), linear-gradient(-45deg, transparent, transparent 7px, rgb(113, 121, 126) 7px, rgb(113, 121, 126) 7.5px, transparent 7.5px, transparent 10px);
background-size: 10px 10px;
filter: drop-shadow(0 0 5px #000);
clip-path: circle(25% at center);
}
.fence>div {
position: absolute;
/*top: 0;*/
left: 0;
right: 0;
/*width: 100%;*/
height: 0.55%;
/*height: 2px;*/
background: green;
}
.fence>div:nth-child(1) {
top: 10%;
}
.fence>div:nth-child(2) {
top: 20%;
}
.fence>div:nth-child(3) {
top: 30%;
}
.fence>div:nth-child(4) {
top: 40%;
}
.fence>div:nth-child(5) {
top: 50%;
}
.fence>div:nth-child(6) {
top: 60%;
}
.fence>div:nth-child(7) {
top: 70%;
}
.fence>div:nth-child(8) {
top: 80%;
}
.fence>div:nth-child(9) {
top: 90%;
}
.fan svg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 70%;
height: 70%;
margin: auto;
}
.slide .fan svg {
animation: fan-spin linear;
animation-duration: 12s;
animation-iteration-count: 1;
animation-delay: 3s;
}
#keyframes fan-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.video-frame {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
iframe {
display: block;
animation: iframe 10s ease forwards;
animation-delay: 8.5s;
opacity: 0;
}
#keyframes iframe {
to {
opacity: 1;
}
}
iframe {
user-select: none;
}
.play {
-webkit-appearance: none;
appearance: none;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
width: 90px;
height: 90px;
border-radius: 50%;
cursor: pointer;
border: 9px solid;
z-index: 1;
background: transparent;
filter: drop-shadow(3px 3px 3px #000000b3);
animation: rotate 700ms linear forwards;
border-color: red transparent red transparent;
}
#keyframes rotate {
0% {
transform: rotate(0deg);
}
99.9% {
border-color: red transparent red transparent;
pointer-events: none;
}
100% {
transform: rotate(360deg);
border-color: #f91f6e;
}
}
.play::before {
content: "";
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 27px solid;
transform: translateX(4px);
animation: triangle 700ms linear forwards;
}
#keyframes triangle {
0% {
opacity: 0;
}
99.9% {
opacity: 0;
}
100% {
border-left-color: #f91f6e;
opacity: 1;
}
}
.play:hover {
box-shadow: 0 0 0 5px rgba(20, 179, 33, 0.5);
}
.play:focus {
outline: 0;
box-shadow: 0 0 0 5px rgba(111, 0, 255, 0.5);
}
.exit {
position: absolute;
top: auto;
bottom: -47.63px;
margin: auto;
right: 0;
left: 0;
width: 47px;
height: 47px;
cursor: pointer;
border-radius: 100%;
background: transparent;
border: 5px solid red;
box-sizing: border-box;
opacity: 0;
pointer-events: none;
clip-path: circle(50%);
}
.slide .exit {
animation: fadeInExit 4s forwards 7.5s;
}
#keyframes fadeInExit {
99% {
pointer-events: none;
}
100% {
pointer-events: initial;
opacity: 1;
}
}
.exit::before,
.exit::after {
content: "";
background-color: red;
width: 47px;
height: 5px;
position: absolute;
top: 0px;
left: -5px;
right: 0;
bottom: 0;
margin: auto;
}
.exit::before {
transform: rotate(45deg);
}
.exit::after {
transform: rotate(-45deg);
}
.hide {
display: none;
}
.video-one {
top: -101%;
/* for testing: fast */
transition: all 1s ease-in 0s;
transition-delay: 0.5s;
}
.video-one.closed {
top: 0%;
}
<div class="container">
<div class="curtain">
<div class="ratio-keeper">
<div class="fence">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="fan">
<svg width="70%" height="70%" viewBox="76 130 381 381">
<g id="fan">
<path fill="#000" stroke="#000"
d="m166.3352 168.6294c5.5396 2.4448 45.2339 54.394 72.7499 91.0151-9.1901-44.8757-21.7959-109.0279-19.9558-114.796 4.1462-12.9949 33.7039-13.5172 41.5845-13.7579 7.8827-.2415 37.4165-1.5221 42.3488 11.1948 2.1872 5.6436-6.4773 70.4506-12.9142 115.8007 25.2309-38.2323 61.6818-92.5089 67.0612-95.2865 12.119-6.2568 33.3898 14.2749 39.1337 19.6768 5.7424 5.402 27.5341 25.3815 22.0294 37.859-2.4441 5.5389-54.3954 45.2354-91.0172 72.7506 44.8757-9.1901 109.0293-21.7959 114.7974-19.9559 12.9927 4.1442 13.5193 33.7032 13.7586 41.5838.2422 7.8819 1.5221 37.4165-11.192 42.3473-5.6471 2.1894-70.4541-6.4765-115.8049-12.9127 38.2323 25.2323 92.5081 61.6783 95.2871 67.0605 6.2581 12.1175-14.2742 33.3877-19.6776 39.133-5.4027 5.7432-25.3815 27.5341-37.8563 22.0279-5.5396-2.4434-45.2361-54.3961-72.7534-91.0143 9.1901 44.8757 21.7952 109.0287 19.9551 114.7953-4.1434 12.9934-33.7026 13.5157-41.5852 13.7586-7.8799.24-37.4165 1.5221-42.3431-11.1936-2.1887-5.6464 6.4779-70.4541 12.9133-115.8071-25.2323 38.2323-61.6824 92.5124-67.0639 95.2908-12.1169 6.256-33.3891-14.2728-39.1337-19.6754-5.7432-5.4027-27.5313-25.383-22.0251-37.8578 2.4434-5.5396 54.394-45.2339 91.0136-72.7526-44.8764 9.1908-109.0266 21.7944-114.7967 19.9566-12.9934-4.1434-13.5171-33.7025-13.7586-41.5852-.2407-7.8806-1.5221-37.4165 11.1963-42.346 5.6443-2.1879 70.4498 6.4752 115.8 12.9121-38.233-25.2316-92.5081-61.6783-95.2865-67.0612-6.256-12.1169 14.2748-33.3913 19.6768-39.1337 5.4006-5.7438 25.3794-27.5333 37.8584-22.0272z" />
</g>
</svg>
</div>
<div class="cross"></div>
<div class="wrap hide">
<div class="video video-frame" data-id=""></div>
</div>
<div class="video-one"></div>
</div>
<a href="https://www.google.com/">
<div class="exit"></div>
</a>
</div>
<button class="play" type="button" aria-label="Open"></button>
</div>

Unable to add music file in audio player

I working on Audio Player for my website so I designed this play and pause animation for UI of audio player but I am having trouble adding an music file into this code. I also tried using some code from an template(https://codepen.io/himalayasingh/pen/QZKqOX) on the following code I made but it didn't workout. Thanks in advance.
let mainCover = document.querySelector("#main_cover");
mainCover.addEventListener("click", () => {
if (mainCover.classList.contains("active")) {
mainCover.classList.remove("active");
mainCover.classList.add("inactive");
} else {
mainCover.classList.remove("inactive");
mainCover.classList.add("active");
}
});
let posts = document.querySelectorAll(".p_img");
imagesLoaded(posts, function () {
document.querySelector("#cover").classList.add("loaded");
document.querySelector("#loading").classList.add("loaded");
});
* {
-webkit-tap-highlight-color: transparent;
}
*:focus {
outline: none;
}
html,
body {
height: 100%;
}
body {
margin: 0;
font-family: Verdana, Geneva, Tahoma, sans-serif;
background-color: #000;
}
#cover {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: none;
}
#cover.loaded {
display: block;
}
#loading {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
z-index: 125;
}
#loading:before {
content: "Loading App ...";
position: absolute;
top: 50%;
right: 0;
left: 0;
color: #fff;
font-size: 14px;
line-height: 14px;
text-align: center;
animation: blink 1.5s ease 0s infinite;
transform: translateY(-50%);
}
#keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0.4;
}
100% {
opacity: 1;
}
}
#loading.loaded {
display: none;
}
.p_img {
position: fixed;
top: 0;
left: 0;
width: 10px;
height: 10px;
opacity: 0;
}
.center {
position: absolute;
top: 50%;
right: 0;
left: 0;
margin: 0 auto;
transform: translateY(-50%);
}
#app {
width: 300px;
margin: 0 auto;
}
#main_cover {
position: relative;
display: block;
width: 300px;
height: 300px;
border: 0;
border-radius: 50%;
background-image: url(https://himalayasingh.github.io/audio-player-play-and-pause-animation-1/img/f1.gif);
background-size: cover;
background-position: 50%;
background-repeat: no-repeat;
cursor: pointer;
overflow: hidden;
transition: 0.1s ease transform;
}
#main_cover:active {
transform: scale(0.9);
}
#main_cover.active {
background-image: url(https://himalayasingh.github.io/audio-player-play-and-pause-animation-1/img/bg.gif);
}
#main_cover.inactive {
background-image: url(https://himalayasingh.github.io/audio-player-play-and-pause-animation-1/img/f1.gif);
}
#main {
width: 54px;
height: 60px;
overflow: hidden;
}
.bar {
position: absolute;
width: 8px;
background-color: #fff;
border-radius: 10px;
transition: 0.4s ease transform, 0.4s ease top, 0.4s ease bottom;
}
#_1 {
top: 0;
bottom: 0;
}
#_2 {
top: -13px;
left: 23px;
height: 60px;
transform: rotateZ(-60deg) translateY(0px);
}
#_3 {
top: 13px;
left: 23px;
height: 60px;
transform: rotateZ(60deg) translateY(0);
}
#_4,
#_5 {
top: 27px;
right: 0;
bottom: 27px;
}
#main_cover.active #_2 {
transform: rotateZ(-60deg) translateY(53px);
}
#main_cover.active #_3 {
transform: rotateZ(60deg) translateY(-53px);
transition-delay: 0.5s;
}
#main_cover.active #_4 {
bottom: 0;
}
#main_cover.active #_5 {
top: 0;
transition-delay: 0.5s;
}
#main_cover.inactive #_2 {
transform: rotateZ(-60deg) translateY(0);
}
#main_cover.inactive #_3 {
transform: rotateZ(60deg) translateY(0);
transition-delay: 0.5s;
}
#main_cover.inactive #_4 {
bottom: 27px;
}
#main_cover.inactive #_5 {
top: 27px;
transition-delay: 0.5s;
}
#app_info {
position: relative;
text-align: center;
padding: 30px 0;
}
#app_info span {
display: inline-block;
color: #adadad;
font-size: 14px;
}
<script src="https://unpkg.com/imagesloaded#4/imagesloaded.pkgd.min.js"></script>
<div id="cover">
<div id="app" class="center">
<div id="main_cover">
<div id="main" class="center">
<div class="bar" id="_1"></div>
<div class="bar" id="_2"></div>
<div class="bar" id="_3"></div>
<div class="bar" id="_4"></div>
<div class="bar" id="_5"></div>
</div>
</div>
<div id="app_info"><span>Radhey Sada Mujh Par</span></div>
</div>
<img src="img/f1.gif" class="p_img">
<img src="img/bg.gif" class="p_img">
</div>
<div id="loading"></div>
I added some simple audio code to make your buttons work. Here is the audio element added to your HTML:
<audio id="audio_player" controls>
<source src="https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/2.mp3" type="audio/mpeg">
<p>Your browser doesn't support HTML5 audio. Here is
a link to the audio instead.</p>
</audio>
Then, you need to get the audio_player in the JavaScript code with:
let audioPlayer = document.querySelector("#audio_player");
and then play and pause it with audio_player.play() and audio_player.pause()
Finally, you need to hide the audio element as you don't need it with a bit of CSS:
audio {
display: none;
}
Here is a link to: more information about audio
let mainCover = document.querySelector("#main_cover");
let audioPlayer = document.querySelector("#audio_player");
mainCover.addEventListener("click", () => {
if (mainCover.classList.contains("active")) {
mainCover.classList.remove("active");
mainCover.classList.add("inactive");
audio_player.pause();
} else {
mainCover.classList.remove("inactive");
mainCover.classList.add("active");
audio_player.play();
}
});
let posts = document.querySelectorAll(".p_img");
imagesLoaded(posts, function() {
document.querySelector("#cover").classList.add("loaded");
document.querySelector("#loading").classList.add("loaded");
});
* {
-webkit-tap-highlight-color: transparent;
}
*:focus {
outline: none;
}
html,
body {
height: 100%;
}
body {
margin: 0;
font-family: Verdana, Geneva, Tahoma, sans-serif;
background-color: #000;
}
audio {
display: none;
}
#cover {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: none;
}
#cover.loaded {
display: block;
}
#loading {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
z-index: 125;
}
#loading:before {
content: "Loading App ...";
position: absolute;
top: 50%;
right: 0;
left: 0;
color: #fff;
font-size: 14px;
line-height: 14px;
text-align: center;
animation: blink 1.5s ease 0s infinite;
transform: translateY(-50%);
}
#keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0.4;
}
100% {
opacity: 1;
}
}
#loading.loaded {
display: none;
}
.p_img {
position: fixed;
top: 0;
left: 0;
width: 10px;
height: 10px;
opacity: 0;
}
.center {
position: absolute;
top: 50%;
right: 0;
left: 0;
margin: 0 auto;
transform: translateY(-50%);
}
#app {
width: 300px;
margin: 0 auto;
}
#main_cover {
position: relative;
display: block;
width: 300px;
height: 300px;
border: 0;
border-radius: 50%;
background-image: url(https://himalayasingh.github.io/audio-player-play-and-pause-animation-1/img/f1.gif);
background-size: cover;
background-position: 50%;
background-repeat: no-repeat;
cursor: pointer;
overflow: hidden;
transition: 0.1s ease transform;
}
#main_cover:active {
transform: scale(0.9);
}
#main_cover.active {
background-image: url(https://himalayasingh.github.io/audio-player-play-and-pause-animation-1/img/bg.gif);
}
#main_cover.inactive {
background-image: url(https://himalayasingh.github.io/audio-player-play-and-pause-animation-1/img/f1.gif);
}
#main {
width: 54px;
height: 60px;
overflow: hidden;
}
.bar {
position: absolute;
width: 8px;
background-color: #fff;
border-radius: 10px;
transition: 0.4s ease transform, 0.4s ease top, 0.4s ease bottom;
}
#_1 {
top: 0;
bottom: 0;
}
#_2 {
top: -13px;
left: 23px;
height: 60px;
transform: rotateZ(-60deg) translateY(0px);
}
#_3 {
top: 13px;
left: 23px;
height: 60px;
transform: rotateZ(60deg) translateY(0);
}
#_4,
#_5 {
top: 27px;
right: 0;
bottom: 27px;
}
#main_cover.active #_2 {
transform: rotateZ(-60deg) translateY(53px);
}
#main_cover.active #_3 {
transform: rotateZ(60deg) translateY(-53px);
transition-delay: 0.5s;
}
#main_cover.active #_4 {
bottom: 0;
}
#main_cover.active #_5 {
top: 0;
transition-delay: 0.5s;
}
#main_cover.inactive #_2 {
transform: rotateZ(-60deg) translateY(0);
}
#main_cover.inactive #_3 {
transform: rotateZ(60deg) translateY(0);
transition-delay: 0.5s;
}
#main_cover.inactive #_4 {
bottom: 27px;
}
#main_cover.inactive #_5 {
top: 27px;
transition-delay: 0.5s;
}
#app_info {
position: relative;
text-align: center;
padding: 30px 0;
}
#app_info span {
display: inline-block;
color: #adadad;
font-size: 14px;
}
<script src="https://unpkg.com/imagesloaded#4/imagesloaded.pkgd.min.js"></script>
<div id="cover">
<div id="app" class="center">
<div id="main_cover">
<div id="main" class="center">
<div class="bar" id="_1"></div>
<div class="bar" id="_2"></div>
<div class="bar" id="_3"></div>
<div class="bar" id="_4"></div>
<div class="bar" id="_5"></div>
</div>
</div>
<div id="app_info"><span>Radhey Sada Mujh Par</span></div>
</div>
<img src="img/f1.gif" class="p_img">
<img src="img/bg.gif" class="p_img">
</div>
<audio id="audio_player" controls>
<source src="https://raw.githubusercontent.com/himalayasingh/music-player-1/master/music/2.mp3" type="audio/mpeg">
<p>Your browser doesn't support HTML5 audio. Here is
a link to the audio instead.</p>
</audio>
<div id="loading"></div>

Right side of image not clickable

How come only the left side of the play image is clickable?
https://jsfiddle.net/g8p1z2m0/
To reproduce Right mouse click on the right side of the play image, nothing happens.
Why is this happening and how is it fixed?
The whole play image should be clickable.
That is the whole issue I am having.
Nothing happens when clicking on the right side of the play image.
(function iife() {
"use strict";
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
const thewrap = curtain.parentElement.querySelector(".container");
show(thewrap);
}
const cover = document.querySelector(".jacketa");
cover.addEventListener("click", coverClickHandler);
}());
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #353198;
}
.curtain {
position: relative;
width: 100%;
height: 100%;
}
.curtain.slide {
height: auto;
min-height: 100%;
overflow: hidden;
}
.panel-left,
.panel-right {
position: absolute;
height: 100%;
width: 50%;
top: 0%;
transition: all ease 10s;
/*background-image: url("https://picsum.photos/600");
background-size: cover;
background-repeat: no-repeat;
background-position: center;*/
overflow: hidden;
}
.panel-left {
left: 0;
/*background-color: rgb(91, 96, 106);*/
}
.panel-right {
right: 0;
/*background-color: rgb(229, 211, 211);*/
}
.panel-left::before,
.panel-right::before {
content: "";
position: absolute;
height: 100%;
width: 200%;
top: 0;
left: 0;
background-image: url("https://picsum.photos/1920/1080");
background-size: auto;
background-repeat: no-repeat;
background-position: 0 0;
}
.panel-right::before {
left: -100%;
}
.curtain.slide .panel-left {
transform: translateX(-100%);
}
.curtain.slide .panel-right {
transform: translateX(100%);
}
.outer {
display: table;
height: 100%;
margin: 0 auto;
}
.tcell {
display: table-cell;
vertical-align: middle;
}
.jacketa {
position: absolute;
top: 40px;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
display: block !important;
}
.j1 .jacketa {
left: 30px;
}
.j2 .jacketa {
right: 30px;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 240px;
height: 260px;
margin: auto;
border-radius: 50%;
transition: 10s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.container {
height: auto;
}
.curtain.slide .j1 {
left: -500%;
}
.curtain.slide .j2 {
left: 500%;
}
.hide {
display: none;
}
<div class="curtain">
<div class="outer">
<div class="tcell">
<div class="container hide">
<div class="container-top">
</div>
</div>
<div class="panel-left"> </div>
<div class="panel-right"> </div>
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>
</div>
</div>
Use document.querySelectorAll(".jacketa") as it has 2 div elements with class jacketa. In your example it return the left part div container inside <div class="j1">.
The Document method querySelector() returns the first Element within the Dom tree that matches the specified selector.
(function iife() {
"use strict";
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
const thewrap = curtain.parentElement.querySelector(".container");
show(thewrap);
}
const covers = document.querySelectorAll(".jacketa");
covers.forEach(cover => cover.addEventListener("click", coverClickHandler));
}());
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #353198;
}
.curtain {
position: relative;
width: 100%;
height: 100%;
}
.curtain.slide {
height: auto;
min-height: 100%;
overflow: hidden;
}
.panel-left,
.panel-right {
position: absolute;
height: 100%;
width: 50%;
top: 0%;
transition: all ease 10s;
/*background-image: url("https://picsum.photos/600");
background-size: cover;
background-repeat: no-repeat;
background-position: center;*/
overflow: hidden;
}
.panel-left {
left: 0;
/*background-color: rgb(91, 96, 106);*/
}
.panel-right {
right: 0;
/*background-color: rgb(229, 211, 211);*/
}
.panel-left::before,
.panel-right::before {
content: "";
position: absolute;
height: 100%;
width: 200%;
top: 0;
left: 0;
background-image: url("https://picsum.photos/1920/1080");
background-size: auto;
background-repeat: no-repeat;
background-position: 0 0;
}
.panel-right::before {
left: -100%;
}
.curtain.slide .panel-left {
transform: translateX(-100%);
}
.curtain.slide .panel-right {
transform: translateX(100%);
}
.outer {
display: table;
height: 100%;
margin: 0 auto;
}
.tcell {
display: table-cell;
vertical-align: middle;
}
.jacketa {
position: absolute;
top: 40px;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
display: block !important;
}
.j1 .jacketa {
left: 30px;
}
.j2 .jacketa {
right: 30px;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 240px;
height: 260px;
margin: auto;
border-radius: 50%;
transition: 10s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.container {
height: auto;
}
.curtain.slide .j1 {
left: -500%;
}
.curtain.slide .j2 {
left: 500%;
}
.hide {
display: none;
}
<div class="curtain">
<div class="outer">
<div class="tcell">
<div class="container hide">
<div class="container-top">
</div>
</div>
<div class="panel-left"> </div>
<div class="panel-right"> </div>
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>
</div>
</div>
You could change something in your JS.
instead of querying jacketmeta const cover = document.querySelector(".jacketa"); you could change it to const cover = document.querySelector(".split-wrap");
Here's your working code https://codepen.io/mcfaith9/pen/VwbzqXP?editors=1010
The reason is that you only add the event to the left side. Both sides have the class .jacketa but you only do this:
const cover = document.querySelector(".jacketa");
cover.addEventListener("click", coverClickHandler);
in this case he only adds the listener to the first element he selects, to make it work on both elements you have to do this:
const covers = document.querySelectorAll(".jacketa");
covers.forEach( cover => cover.addEventListener("click", coverClickHandler) );

Fade out and remove an element

What I would like to do is fade out and remove an element after a few seconds.
It would be initiated after the play image is clicked.
Have it set so that after the play image is clicked, then a fade out transition would occur a few seconds after, then the element would be removed from the page.
First the play image splits apart.
Then, a few seconds after, a fade out transition would occur on the play image, but not right away, a set time.
And after that it would be removed from the page.
That's what I am trying to do.
code https://jsfiddle.net/caer51sw/
(function iife() {
"use strict";
function show(el) {
el.classList.remove("hide");
}
function hide(el) {
el.classList.add("hide");
}
function coverClickHandler(evt) {
const cover = evt.currentTarget;
hide(cover);
const curtain = document.querySelector(".curtain");
curtain.classList.add("slide");
const thewrap = curtain.parentElement.querySelector(".container");
show(thewrap);
}
const cover = document.querySelector(".jacketa");
cover.addEventListener("click", coverClickHandler);
}());
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #353198;
}
.curtain {
position: relative;
width: 100%;
height: 100%;
}
.curtain.slide {
height: auto;
min-height: 100%;
overflow: hidden;
}
.panel-left,
.panel-right {
position: absolute;
height: 100%;
width: 50%;
top: 0%;
transition: all ease 10s;
/*background-image: url("https://picsum.photos/600");
background-size: cover;
background-repeat: no-repeat;
background-position: center;*/
overflow: hidden;
}
.panel-left {
left: 0;
/*background-color: rgb(91, 96, 106);*/
}
.panel-right {
right: 0;
/*background-color: rgb(229, 211, 211);*/
}
.panel-left::before,
.panel-right::before {
content: "";
position: absolute;
height: 100%;
width: 200%;
top: 0;
left: 0;
background-image: url("https://picsum.photos/1920/1080");
background-size: auto;
background-repeat: no-repeat;
background-position: 0 0;
}
.panel-right::before {
left: -100%;
}
.curtain.slide .panel-left {
transform: translateX(-100%);
}
.curtain.slide .panel-right {
transform: translateX(100%);
}
.outer {
display: table;
height: 100%;
margin: 0 auto;
}
.tcell {
display: table-cell;
vertical-align: middle;
}
.jacketa {
position: absolute;
top: 40px;
width: 180px;
height: 180px;
cursor: pointer;
border-radius: 50%;
background: #130e85;
border: 3px solid #f91f6e;
box-sizing: border-box;
box-shadow: 0 0 20px 2px #f9066bf7;
display: block !important;
}
.j1 .jacketa {
left: 30px;
}
.j2 .jacketa {
right: 30px;
}
.jacketa .coversvg {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
cursor: pointer;
}
.jacketa .coversvg {
width: 70px;
height: 75.4px;
fill: none;
stroke-width: 4px;
stroke-miterlimit: 10;
}
.jacketa .coversvg .back {
stroke: #000;
opacity: 0.15;
}
.jacketa .coversvg .front {
stroke: #08f9ff;
stroke-dasharray: 150;
stroke-dashoffset: 1500;
animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes flicker-1 {
0%,
100% {
opacity: 1;
}
41.99% {
opacity: 1;
}
42% {
opacity: 0;
}
43% {
opacity: 0;
}
43.01% {
opacity: 1;
}
47.99% {
opacity: 1;
}
48% {
opacity: 0;
}
49% {
opacity: 0;
}
49.01% {
opacity: 1;
}
}
.split-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 240px;
height: 260px;
margin: auto;
border-radius: 50%;
transition: 10s ease;
}
.j1 {
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.j2 {
position: absolute;
left: 50%;
top: 0;
width: 50%;
height: 100%;
overflow: hidden;
transition: 10s ease;
}
.curtain.slide .j1 {
transform: translateX(-529%);
}
.curtain.slide .j2 {
transform: translateX(529%);
}
.hide {
display: none;
}
<div class="curtain">
<div class="outer">
<div class="tcell">
<div class="container hide">
<div class="container-top">
</div>
</div>
<div class="panel-left"> </div>
<div class="panel-right"> </div>
<div class="split-wrap">
<div class="j1">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
<div class="j2">
<div class="jacketa" title="[ Enjoy The Music ]">
<svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
<title>[ Enjoy The Music ]</title>
<path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
<path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
</svg>
</div>
</div>
</div>
</div>
</div>
</div>

How can I get two separate animations to play upon a single onclick?

Let me start off by saying I am new to CSS/HTML coding in general. Mostly learned by breaking down others codes and rebuilding them. So, I am by no means a professional and maybe in well over my head for this. My terminology may be off as well. Sorry in advance.
What I would like to do is open two separate animations upon clicking one button, is that possible? I have a feeling I will need to learn Javascript to do this but I wasn't too sure if there was a way to do it strictly via CSS.
So the "Where are you?" and the 'BEHIND' animation wouldn't play until the button is clicked instead of the "Where are you?" just playing upon load.
#Screen {
position: fixed;
left: 0px;
right: 5px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
background-color: #909090;
background-image: url('https://www.transparenttextures.com/patterns/dotnoise-light-grey.png');
border: 2px solid #111;
z-index: 2
}
#Button1 {
position: fixed;
left: 0px;
right: 175px;
top: 0px;
bottom: 110px;
margin: auto;
Height: 15px;
width: 35px;
border-radius: 30px;
border: 1px solid #333;
background-image: url('https://i.pinimg.com/600x315/ef/a4/54/efa454458c927ff79e21b898bbd446f0.jpg');
background-color: #101010;
z-index: 3;
}
.tab div {
display: none;
position: fixed;
left: 0px;
right: 5px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
padding: px;
background-color: #F0FFF0;
background-image: url('https://www.transparenttextures.com/patterns/asfalt-light.png');
box-shadow: 1px 1px 10px 1px #ffffff;
z-index: 4;
overflow: hidden;
}
.tab div:target {
display: block;
}
/*Flicker-in-1 is for the screen to "flicker on"*/
.flicker-in-1 div {
display: none;
position: fixed;
left: 0px;
right: 5px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
padding: px;
background-color: #F0FFF0;
background-image: url('https://www.transparenttextures.com/patterns/asfalt-light.png');
box-shadow: 1px 1px 10px 1px #ffffff;
z-index: 4;
overflow: hidden;
-webkit-animation: flicker-in-1 2s linear 1s both;
animation: flicker-in-1 2s linear 1s both;
}
/*Minified this block of code*/
#-webkit-keyframes flicker-in-1 {
0% {
opacity: 0;
}
10% {
opacity: 0;
}
10.1% {
opacity: 1;
}
10.2% {
opacity: 0;
}
20% {
opacity: 0;
}
20.1% {
opacity: 1;
}
20.6% {
opacity: 0;
}
30% {
opacity: 0;
}
30.1% {
opacity: 1;
}
30.5% {
opacity: 1;
}
30.6% {
opacity: 0;
}
45% {
opacity: 0;
}
45.1% {
opacity: 1;
}
50% {
opacity: 1;
}
55% {
opacity: 1;
}
55.1% {
opacity: 0;
}
57% {
opacity: 0;
}
57.1% {
opacity: 1;
}
60% {
opacity: 1;
}
60.1% {
opacity: 0;
}
65% {
opacity: 0;
}
65.1% {
opacity: 1;
}
75% {
opacity: 1;
}
75.1% {
opacity: 0;
}
77% {
opacity: 0;
}
77.1% {
opacity: 1;
}
85% {
opacity: 1;
}
85.1% {
opacity: 0;
}
86% {
opacity: 0;
}
86.1% {
opacity: 1;
}
100% {
opacity: 1;
}
}
.text-focus-in {
position: fixed;
left: 0px;
right: 600px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
background-color: #909090;
background-image: url('https://www.transparenttextures.com/patterns/dotnoise-light-grey.png');
border: 2px solid #111;
z-index: 2 -webkit-animation: text-focus-in 2s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
animation: text-focus-in 2s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
}
#-webkit-keyframes text-focus-in {
0% {
-webkit-filter: blur(12px);
filter: blur(12px);
opacity: 0;
}
100% {
-webkit-filter: blur(0px);
filter: blur(0px);
opacity: 1;
}
}
#keyframes text-focus-in {
0% {
-webkit-filter: blur(12px);
filter: blur(12px);
opacity: 0;
}
100% {
-webkit-filter: blur(0px);
filter: blur(0px);
opacity: 1;
}
}
h1 {
font-family: "Orbitron";
text-align: center;
}
<div id="Screen"></div>
<div class="text-focus-in">Where are you? </div>
<a href="#Behind">
<div id="Button1"></div>
</a>
<div class="flicker-in-1 tab">
<div id="Behind">
<h1>BEHIND</h1>
</div>
</div>
You can use this little trick. It relies on a checkbox next to the animatable thing and tracking its state ( using a selector like #toggle:checked ~ #animatable_element). You can toggle it clicking the label.
#animatable_element {
width: 100px;
height: 100px;
background: orange;
}
#toggle {
display: none; /* optional */
}
#toggle:checked ~ #animatable_element {
animation-name: example;
animation-duration: 1s;
animation-iteration-count: infinite;
}
#keyframes example {
0% {background-color: orange;}
50% {background-color: yellow;}
100% {background-color: orange}
}
#animatable_element_2 {
width: 100px;
height: 100px;
background: blue;
}
#toggle:checked ~ #animatable_element_2 {
animation-name: example_2;
animation-duration: 1s;
animation-iteration-count: infinite;
}
#keyframes example_2 {
0% {background-color: blue;}
50% {background-color: purple;}
100% {background-color: blue}
}
<label for='toggle'>Click me to start or stop the animation</label>
<input id='toggle' type='checkbox'/>
<div id='animatable_element_2'></div>
<div id='animatable_element'></div>
CSS
.animation-box {
background-color:gray;
width: 250px;
height: 250px;
}
HTML
<div class="animation-box">
<span class="fade-in-and-fade-out-animation">"Where are you?"</span>
<h1 class="pop-up-blinking-animation">RIGHT BEHIND YOU!!</h1>
</div>
<button class="btn">Start Animation</button>
Solution Trigger animation using the button element and layer the animations on the same container, or you may need to dig into JavaScript, specifically into JS queues.
This works by using javascript: element.classList.add("flicker-in-1");
Adding the class's when button is clicked.
function here() {
var element = document.getElementById("here");
var element2 = document.getElementById("Behind");
element.classList.add("flicker-in-1");
element.classList.add("tab");
element2.classList.remove("hide");
}
#Screen {
position: fixed;
left: 0px;
right: 5px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
background-color: #909090;
background-image: url('https://www.transparenttextures.com/patterns/dotnoise-light-grey.png');
border: 2px solid #111;
z-index: 2
}
#Button1 {
position: fixed;
left: 0px;
right: 175px;
top: 0px;
bottom: 110px;
margin: auto;
Height: 15px;
width: 35px;
border-radius: 30px;
border: 1px solid #333;
background-image: url('https://i.pinimg.com/600x315/ef/a4/54/efa454458c927ff79e21b898bbd446f0.jpg');
background-color: #101010;
z-index: 3;
cursor: pointer;
}
.tab div {
display: block;
position: fixed;
left: 0px;
right: 5px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
padding: px;
background-color: #F0FFF0;
background-image: url('https://www.transparenttextures.com/patterns/asfalt-light.png');
box-shadow: 1px 1px 10px 1px #ffffff;
z-index: 4;
overflow: hidden;
}
/*Flicker-in-1 is for the screen to "flicker on"*/
.flicker-in-1 div {
display: block;
position: fixed;
left: 0px;
right: 5px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
padding: 0px;
background-color: #F0FFF0;
background-image: url('https://www.transparenttextures.com/patterns/asfalt-light.png');
box-shadow: 1px 1px 10px 1px #ffffff;
z-index: 4;
overflow: hidden;
-webkit-animation: flicker-in-1 0s linear 0s both;
animation: flicker-in-1 0.5s linear 0s both;
animation-delay: 0s;
}
/*Minified this block of code*/
#-webkit-keyframes flicker-in-1 {
0% {
opacity: 0;
}
10% {
opacity: 0;
}
10.1% {
opacity: 1;
}
10.2% {
opacity: 0;
}
20% {
opacity: 0;
}
20.1% {
opacity: 1;
}
20.6% {
opacity: 0;
}
30% {
opacity: 0;
}
30.1% {
opacity: 1;
}
30.5% {
opacity: 1;
}
30.6% {
opacity: 0;
}
45% {
opacity: 0;
}
45.1% {
opacity: 1;
}
50% {
opacity: 1;
}
55% {
opacity: 1;
}
55.1% {
opacity: 0;
}
57% {
opacity: 0;
}
57.1% {
opacity: 1;
}
60% {
opacity: 1;
}
60.1% {
opacity: 0;
}
65% {
opacity: 0;
}
65.1% {
opacity: 1;
}
75% {
opacity: 1;
}
75.1% {
opacity: 0;
}
77% {
opacity: 0;
}
77.1% {
opacity: 1;
}
85% {
opacity: 1;
}
85.1% {
opacity: 0;
}
86% {
opacity: 0;
}
86.1% {
opacity: 1;
}
100% {
opacity: 1;
}
}
.text-focus-in {
position: fixed;
left: 0px;
right: 600px;
top: 0px;
bottom: 330px;
margin: auto;
Height: 100px;
width: 210px;
border-radius: 10px;
background-color: #909090;
background-image: url('https://www.transparenttextures.com/patterns/dotnoise-light-grey.png');
border: 2px solid #111;
z-index: 2 -webkit-animation: text-focus-in 2s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
animation: text-focus-in 2s cubic-bezier(0.550, 0.085, 0.680, 0.530) both;
}
#-webkit-keyframes text-focus-in {
0% {
-webkit-filter: blur(12px);
filter: blur(12px);
opacity: 0;
}
100% {
-webkit-filter: blur(0px);
filter: blur(0px);
opacity: 1;
}
}
#keyframes text-focus-in {
0% {
-webkit-filter: blur(12px);
filter: blur(12px);
opacity: 0;
}
100% {
-webkit-filter: blur(0px);
filter: blur(0px);
opacity: 1;
}
}
h1 {
font-family: "Orbitron";
text-align: center;
}
.hide {
display: none;
}
<div id="Screen"></div>
<div class="text-focus-in">Where are you? </div>
<button id="Button1" onclick="here();"></button>
<div id="here">
<div class="hide" id="Behind">
<h1>BEHIND</h1>
</div>
</div>
PS: You have to Expand snippet to see it correctly.

Categories

Resources