Engaging dual overlay dynamic made possible with absolute positioning, overflows, and understanding the z-stacking context. Click anywhere to change the width of the blue overlay!
Created
January 16, 2019 00:37
-
-
Save thiagolopes-dev/e61611ac525b7a7cf34b9cf3d2a01853 to your computer and use it in GitHub Desktop.
Luna: Schrödinger's Wolf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Original Image provided by Freepiks at https://www.freepik.com/free-vector/triangle-wolf-design_723866.htm#term=wolf&page=1&position=3 | |
I used enginethemes page for *inspiration* ¯\_(ツ)_/¯ | |
Shadow => https://static.enginethemes.com/main/img/shadow.png --> | |
<div id="hero"> | |
<div class="view view-after" style="width: 50vw;" id="viewAfter"> | |
<div class="wrapper-after"> | |
<div class="logo"> | |
<h2> <img src="http://res.cloudinary.com/dub9ykyuq/image/upload/v1517696936/wolfsvg_hxf2jz.png" alt=""> Jean Villalobos</h2> | |
</div> | |
<div class="img-wrapper"> | |
<img src="http://res.cloudinary.com/dub9ykyuq/image/upload/v1517697588/Untitled_wcfedl.png" alt=""> | |
</div> | |
<div class="img-shadow"></div> | |
</div> | |
</div> | |
<div class="view view-before" id="viewBefore"> | |
<div class="wrapper-before"> | |
<div class="logo"> | |
<h2> <img src="http://res.cloudinary.com/dub9ykyuq/image/upload/v1517696936/wolfsvg_hxf2jz.png" alt=""> Jean Villalobos</h2> | |
</div> | |
<div class="img-wrapper"> | |
<img src="http://res.cloudinary.com/dub9ykyuq/image/upload/v1517696936/wolfsvg_hxf2jz.png" alt=""> | |
</div> | |
<div class="img-shadow"></div> | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const viewAfter = document.getElementById("viewAfter"); | |
document.addEventListener("click", changeWidth); | |
function changeWidth(e) { | |
viewAfter.style = "width: " + e.clientX + "px;"; | |
} | |
// Particles with mojs | |
// count = 10 seems to be the magic number for performance on mobile and older devices | |
let innerRadius; | |
let outerRadius; | |
let smallSize = 20; | |
let bigSize = 25; | |
function setRadius() { | |
if(window.innerWidth <= 425 ) { | |
innerRadius = parseInt(window.innerWidth * 0.1); | |
outerRadius = parseInt(window.innerWidth * 0.6); | |
} | |
else if(window.innerWidth > 425 && window.innerWidth < 1080) { | |
innerRadius = parseInt(window.innerWidth * 0.07); | |
outerRadius = parseInt(window.innerWidth * 0.28); | |
} | |
else if (window.innerWidth > 1080) { | |
innerRadius = parseInt(window.innerHeight * .15); | |
outerRadius = parseInt(window.innerHeight * .3); | |
} | |
else { | |
} | |
} | |
setRadius(); | |
const DURATION = 1000; | |
const count = 15; | |
let smoke = new mojs.Burst({ | |
opacity: .7, | |
parent: "#viewAfter", | |
left: 0, top: 0, | |
degree: 270, | |
angle: -135, | |
count: count, | |
radius: { [innerRadius] : outerRadius }, | |
children: { | |
fill: ['white', "#2A3A3F"], | |
pathScale: 'rand(0.5, 1)', | |
radius: 'rand(12, 13)', | |
swirlSize: 'rand(20, 25)', | |
swirlFrequency: 'rand(2, 4)', | |
direction: [ 1, -1 ], | |
duration: `rand(${1*DURATION}, ${2*DURATION})`, | |
delay: 'rand(0, 2000)', | |
easing: 'quad.out', | |
isSwirl: true, | |
isForce3d: true, | |
} | |
}); | |
let smokeBefore = new mojs.Burst({ | |
opacity: .7, | |
parent: "#viewBefore", | |
left: 0, top: 0, | |
degree: 270, | |
angle: -135, | |
count: count, | |
radius: { [innerRadius] : outerRadius }, | |
children: { | |
fill: ['#397fda', "#2A3A3F"], | |
pathScale: 'rand(0.5, 1)', | |
radius: 'rand(12, 13)', | |
swirlSize: `rand(20, 25)`, | |
swirlFrequency: 'rand(2, 4)', | |
direction: [ 1, -1 ], | |
duration: `rand(${1*DURATION}, ${2*DURATION})`, | |
delay: 'rand(0, 2000)', | |
easing: 'quad.out', | |
isSwirl: true, | |
isForce3d: true, | |
} | |
}); | |
smokeBefore.tune({ x: "50vw", y: "50vh" }).generate().replay(); | |
smoke.tune({ x: "50vw", y: "50vh" }).generate().replay(); | |
let leftParticles = new mojs.Tween({ | |
repeat: 99999, | |
delay: 3000, | |
onUpdate: function() { | |
smokeBefore.tune({ x: "50vw", y: "50vh" }).generate().replay(); | |
} | |
}).play(); | |
let rightParticles = new mojs.Tween({ | |
repeat: 99999, | |
delay: 3000, | |
onUpdate: function() { | |
smoke.tune({ x: "50vw", y: "50vh" }).generate().replay(); | |
} | |
}).play(500); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/mojs/0.265.6/mo.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: sans-serif; | |
margin: 0; | |
} | |
.logo { | |
padding: 0 15px; | |
margin: 0; | |
width: 100%; | |
color: white; | |
position: absolute; | |
left: 0; | |
overflow: hidden; | |
} | |
.logo h2 { | |
margin: 0; | |
} | |
.view-before .logo { | |
color: black; | |
} | |
.logo img { | |
width: 30px; | |
vertical-align: bottom; | |
} | |
.view { | |
position: absolute; | |
width: 100%; | |
height: 100%; | |
overflow: hidden; | |
} | |
.view-before { | |
z-index: 100; | |
} | |
.view-after { | |
background-color: #397fda; | |
z-index: 200; | |
transition: width 1s ease-in-out; | |
} | |
.wrapper-after , .wrapper-before { | |
/* Make Wrapper take the whole screen for relative positioning of wrapper */ | |
height: 100%; | |
width: 100vw; | |
position: absolute; | |
} | |
.img-wrapper { | |
/* Fixed width for consistency on resize & movement */ | |
position: relative; | |
top: 50%; | |
transform: translate(-4px, -50%); | |
left: 0; | |
right: 0; | |
margin: 0 auto; | |
width: 32vh; | |
} | |
/* Text */ | |
.text-after, .text-before { | |
overflow: hidden; | |
} | |
.text-after h2, .text-before h2 { | |
position: absolute; | |
width: 30%; | |
padding: 0 2%; | |
top: 50%; | |
transform: translatey(-50%); | |
} | |
.text-after h2:nth-child(1) , .text-before h2:nth-child(1) { | |
left: 0; | |
} | |
.text-after h2:nth-child(2) , .text-before h2:nth-child(2) { | |
right: 0; | |
} | |
.text-after { | |
color: white; | |
} | |
.text-before { | |
color: black; | |
} | |
/* Exported to PNG */ | |
.img-wrapper img { | |
width: 100%; | |
animation: float 3s infinite; | |
} | |
.img-shadow { | |
background: url(https://static.enginethemes.com/main/img/shadow.png) no-repeat center center; | |
width: 250px; | |
height: 24px; | |
left: 0; | |
right: 0; | |
margin: 0 auto; | |
position: absolute; | |
bottom: 18%; | |
animation: shadowMagnify 3s infinite; | |
} | |
/* Menu */ | |
.menu { | |
position: absolute; | |
right: 0; | |
z-index: 1000; | |
} | |
.menu li { | |
margin-right: 10px; | |
display: inline-block; | |
} | |
.menu a { | |
font-weight: bold; | |
text-decoration: none; | |
color: #2A3A3F; | |
} | |
/* Animations */ | |
@keyframes shadowMagnify { | |
0% { | |
transform: scale(0.7); | |
opacity: 0.7; | |
} | |
50% { | |
transform: scale(1); | |
opacity: 1; | |
} | |
100% { | |
transform: scale(0.7); | |
opacity: 0.7; | |
} | |
} | |
@keyframes float { | |
0% { | |
transform: translatey(0%); | |
} | |
50% { | |
transform: translatey(8%); | |
} | |
100% { | |
transform: translatey(0%); | |
} | |
} | |
/* Particles */ | |
#viewBefore div[data-name="mojs-shape"] { | |
position: absolute; | |
z-index: -10; | |
} | |
#viewAfter div[data-name="mojs-shape"] { | |
position: absolute; | |
z-index: -10; | |
} | |
/* Media Queries */ | |
@media only screen | |
and (min-width: 320px) | |
and (max-width: 736px) | |
and (-webkit-min-device-pixel-ratio: 1) { | |
/*Header*/ | |
.text-after , .text-before { | |
display: none; | |
} | |
.logo h2 { | |
font-size: 18px; | |
} | |
.menu { | |
display: none; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment