const el = document.querySelector('.element');
const wrapper = document.querySelector('.wrapper');
window.addEventListener('scroll', () => {
const wrapperBox = wrapper.getBoundingClientRect();
const elBox = el.getBoundingClientRect();
const isInside = elBox.top > wrapperBox.top && elBox.bottom < wrapperBox.bottom;
el.style.opacity = isInside ? 1 : 0;
});
transition: opacity 0.3s;
opacity: 0;