Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

vanilla javascript fade out

<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>
Comment

javascript fadein fadeout

#slideSource {
  opacity: 1;
  transition: opacity 1s; 
}

#slideSource.fade {
  opacity: 0;
}
Comment

JavaScript Element fade out

/*@lang css

#target {
    height: 100px;
    background-color: red;
    transition: opacity 1s;
}

*/

const target = document.getElementById("target");

target.addEventListener('click', () => target.style.opacity = '0');
// If you want to remove it from the page after the fadeout
target.addEventListener('transitionend', () => target.remove());
Comment

javascript fadein fadeout

var slideSource = document.getElementById('slideSource');

document.getElementById('handle').onclick = function () {
  slideSource.classList.toggle('fade');
}
Comment

javascript fadein fadeout

<button id="handle">Fade</button> 
<div id="slideSource">Whatever you want here - images or text</div>
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery validate all input fields 
Javascript :: peerjs 
Javascript :: how to run cypress test 
Javascript :: how to create an array in javascript 
Javascript :: remove from string javascript regex 
Javascript :: trigger a button click with javascript on the enter key in a text box 
Javascript :: express controller 
Javascript :: get window height javascript 
Javascript :: how to get last item in array in javascript 
Javascript :: document.queryselector 
Javascript :: react merge two objects 
Javascript :: try catch js 
Javascript :: create multidimensional array javascript for loop 
Javascript :: sum array without loop javascript 
Javascript :: laravel vuejs lang 
Javascript :: jquery ajax send custom data after serialize 
Javascript :: react-data-table-component cell action 
Javascript :: import react js video player 
Javascript :: Add remove link dropzone 
Javascript :: how to use cookies in react class component 
Javascript :: console.log(...) is not a function 
Javascript :: js access array in array 
Javascript :: How to get previous url in nextjs 
Javascript :: Make Floating label TextInput in react native 
Javascript :: express cookieparser 
Javascript :: javascript clone element 
Javascript :: simple user agent parse js 
Javascript :: angular9 spy 
Javascript :: javascript this in settimeout 
Javascript :: networkx get nodes 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =