<div class="p-mv">
<div class="p-mv__title">
<div class="p-anima-6 __anima" id="js-anima-6">
<span class="p-anima-6__item">
<span>The best of both worlds</span>
</span>
<br>
<span class="p-anima-6__item">
<span>Monkey business</span>
</span>
</div>
</div>
</div>
<button type="button" data-reload="js-anima-6" id="js-reload">リロード</button>
.p-anima-6__item {
display: inline-block;
position: relative;
}
.p-anima-6__item::before {
content: "";
display: block;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 100%;
bottom: 0;
}
.p-anima-6.__anima .p-anima-6__item::before {
animation: anima_bg_6 0.9s ease-out 1 forwards;
}
.p-anima-6__item:nth-of-type(2)::before {
animation-delay: 0.3s !important;
}
.p-anima-6__item span {
position: relative;
z-index: 1;
opacity: 0;
}
.p-anima-6.__anima .p-anima-6__item span {
animation: anima_fadein_6 0.5s ease-out 0.9s 1 forwards;
}
@keyframes anima_fadein_6 {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes anima_bg_6 {
0% {
left: 0;
right: 100%;
}
40% {
left: 0;
right: 0;
}
60% {
left: 0;
right: 0;
}
100% {
left: 100%;
right: 0;
}
}
/* アニメーションとは関係のないスタイル(ボタンの見た目など) */
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100vh;
}
button {
margin-top: 40px;
}
.p-mv {
display: flex;
align-items: center;
background-image: url("https://picsum.photos/900/600");
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: cover;
padding: 40px;
height: 200px;
position: relative;
}
.p-mv::before {
content: "";
display: block;
background-color: rgba(51, 51, 51, 0.5);
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.p-mv__title {
color: #fff;
font-size: 56px;
font-weight: bold;
line-height: 1.3;
position: relative;
z-index: 1;
}
@media screen and (max-width: 640px) {
.p-mv__title {
font-size: 24px;
}
}
document.querySelector('#js-reload').addEventListener('click', (_ev) => {
const target = _ev.target.getAttribute('data-reload');
document.querySelector(`#${target}`).classList.remove('__anima');
setTimeout(() => {
document.querySelector(`#${target}`).classList.add('__anima');
}, 500);
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.