<div class="buttons">
<button class="connect" onclick="connect()">Connect</button>
<button class="red disconnect disabled" onclick="disconnect()">Disconnect</button>
</div>
<div class="text">
<div class="inner">
<h3 class="active">"If you're already a front-end developer, well, pretend you're also wearing a pirate hat"</h3>
<div class="border active"></div>
</div>
<div class="inner">
<img class="active" src="http://jacksprw.com/picture_library/zfidg15.jpg">
</div>
</div>
body{
height: 210vh;
position: relative;
}
.text{
position: relative;
top: 150vh;
width: 100%;
height: 330px;
display: flex;
align-items: center;
}
h3{
padding: 20px;
box-sizing: border-box;
line-height: 35px;
font-size: 28px;
color: #333;
font-family: sans-serif;
width: 70%;
position: absolute;
left: 0;
opacity: 0;
transition: left 0.5s ease-in, opacity 0.5s ease-in;
}
.inner{
width: 50%;
height: 100%;
position: relative;
display: flex;
flex-direction: column;
}
img{
position: absolute;
padding: 40px;
box-sizing: border-box;
width: 70%;
right: 0;
opacity: 0;
transition: right 0.5s ease-in, opacity 0.5s ease-in;
}
.text h3.active{
left: 30%;
opacity:1;
transition: left 0.5s ease-in, opacity 0.5s ease-in;
}
.text img.active{
right: 30%;
opacity:1;
transition: right 0.5s ease-in, opacity 0.5s ease-in;
}
.border{
height: 5px;
width: 0;
background: red;
transition: width 0.5s ease-in;
position: absolute;
bottom: 125px;
}
.active.border{
width: 100%;
transition: width 0.5s ease-in
}
button {
font-size: 16px;
margin: 10px 20px;
padding: 10px 20px;
background: #07ab0e;
color: #fff;
border: 0;
font-weight: bold;
border-radius: 3px;
cursor: pointer;
}
.red {
background: #F44336;
}
.disabled {
pointer-events: none;
opacity: 0.5;
}
.buttons{
position: fixed;
top: 0;
width: 100%;
padding: 30px;
display: flex;
justify-content: center;
}
</style>
var box = document.querySelector('.text'); //Target
var config = { // we can set root, rootMargin, threshold.
}
var callback = (entries, observer)=>{
for( let i=0;i<entries.length;i++){
entries[i].target.querySelectorAll('.border')[0].classList.toggle('active');
setTimeout(()=>{
entries[i].target.querySelector('h3').classList.toggle('active');
setTimeout(()=>{
entries[i].target.querySelector('img').classList.toggle('active');
}, 500, entries)
}, 500, entries)
}
}
var observer = new IntersectionObserver(callback, config);
let connect = () =>{
observer.observe(box); //start observer
document.querySelector('.connect').classList.add('disabled');
document.querySelector('.disconnect').classList.remove('disabled');
}
let disconnect = () =>{
observer.unobserve(box); //stop observer
document.querySelector('.connect').classList.remove('disabled');
document.querySelector('.disconnect').classList.add('disabled');
document.querySelector('img').classList.add('active');
document.querySelector('h3').classList.add('active');
document.querySelector('.border').classList.add('active');
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.