<div id="target">Click to fade</div>
<script>
function fadeOutEffect() {
var fadeTarget = document.getElementById("target");
var fadeEffect = setInterval(function () {
if (!fadeTarget.style.opacity) {
fadeTarget.style.opacity = 1;
}
if (fadeTarget.style.opacity > 0) {
fadeTarget.style.opacity -= 0.1;
} else {
clearInterval(fadeEffect);
}
}, 200);
}
document.getElementById("target").addEventListener('click', fadeOutEffect)
</script>
<style>
#target {
height: 100px;
background-color: red;
}
</style>
#slideSource {
opacity: 1;
transition: opacity 1s;
}
#slideSource.fade {
opacity: 0;
}
event.target.style.transition = '0.8s';
event.target.style.opacity = 0;
var slideSource = document.getElementById('slideSource');
document.getElementById('handle').onclick = function () {
slideSource.classList.toggle('fade');
}
<button id="handle">Fade</button>
<div id="slideSource">Whatever you want here - images or text</div>
Run code snippet