// ===========================================================
// This is for the entrence and exit of the logo and menu icon
// ===========================================================
var objectLeft = document.querySelector('.object-left');
var objectRight = document.querySelector('.object-right');
var objectLeftB = document.querySelector('.object-left-b');
var objectRightB = document.querySelector('.object-right-b');
var previousScroll = 0;
// Function to handle the 'transitionend' event
function endTransition(e) {
if (e.propertyName === 'transform') {
this.style.transform = '';
}
}
// Add 'transitionend' listeners
[objectLeft, objectRight, objectLeftB, objectRightB].forEach(ele => {
ele.addEventListener('transitionend', endTransition);
});
window.addEventListener("scroll", function(){
var vh = window.innerHeight * 0.01; //1% of viewport height
var currentScroll = window.pageYOffset;
if(currentScroll > 100 * vh && previousScroll <= currentScroll) { // moment of entrance
objectLeft.style.opacity = '1';
objectRight.style.opacity = '1';
objectLeftB.style.opacity = '1';
objectRightB.style.opacity = '1';
}
if(previousScroll > currentScroll && currentScroll <= 100 * vh) { // moment of exit
objectLeft.style.opacity = '0';
objectRight.style.opacity = '0';
objectLeftB.style.opacity = '0';
objectRightB.style.opacity = '0';
// Slide out animation
objectLeft.style.transform = 'translateX(-150px)';
objectRight.style.transform = 'translateX(150px)';
objectLeftB.style.transform = 'translateX(-150px)';
objectRightB.style.transform = 'translateX(150px)';
}
previousScroll = currentScroll;
});
// ==================================
// This is standalone script for the color change (previous part is optional).
// Applay the class .replace to the section where you want the fixed element to change color (meaning, being replaced)
// ==================================
// Detect request...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.