<script>
document.addEventListener("DOMContentLoaded", function() {
(function () {
const chameleonID = '#rec265279589';
const scrolldistance = 100; //Дистанция появления меню
let menuHeight = 0;
let sector = 0;
let ancArr = [];
let menuElement = null;
let resizeTimeout = null;
function initChameleon() {
menuElement = document.querySelector(chameleonID);
if (!menuElement) return;
menuElement.classList.add('fixed');
setTimeout(() => menuElement.classList.add('transtime'), 500);
findAnchors();
setupEventListeners();
getSector();
};
function findAnchors() {
const anchors = document.querySelectorAll('a[name="chameleon"]');
ancArr = Array.from(anchors).map(anchor => {
const rect = anchor.getBoundingClientRect();
return rect.top + window.pageYOffset;
});
if (menuElement) {
menuHeight = menuElement.offsetHeight;
};
};
function getSector() {
const topDoc = window.pageYOffset || document.documentElement.scrollTop;
if (topDoc > scrolldistance) {
menuElement.classList.add('chameleonshow');
} else {
menuElement.classList.remove('chameleonshow');
};
for (let i = 0; i < ancArr.length; i++) {
if ((topDoc + menuHeight) < ancArr[i]) {
sector = i;
break;
} else if (i === ancArr.length - 1) {
sector = i + 1;
break;
};
};
if (sector % 2) {
menuElement.classList.add('chameleon');
} else {
menuElement.classList.remove('chameleon');
};
};
function setupEventListeners() {
window.addEventListener('scroll', getSector, { passive: true });
window.addEventListener('resize', function() {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(findAnchors, 100);
});
};
initChameleon();
})();
});
</script>
<style> .fixed {
position: fixed;
width: 100%;
top: 0px;
z-index: 9999;
transform: translateY(-100%);
}
.chameleonshow{
transform: translateY(0%) !important;
}
.transtime{
transition: all 0.4s cubic-bezier(0, 0, 0.8, 1.0)
}
.fixed .t396__artboard {
transition: all 0.4s ease
}
div.chameleon .t396__artboard {
background-color: #333 !important
}
div.chameleon .tn-atom {
color: #ffffff !important
}
.icon-white{
display:none
}
div.chameleon .icon-white{
display:block
}
div.chameleon .icon-black{
display:none
}
</style>