Answers for "fade out js"

5

on click fade out jquery

$(document).ready(function(){
  $("button").click(function(){
    $("p").fadeOut(2500);
  });
});
Posted by: Guest on February-05-2020
1

jquery on click fade out element

$(document).ready(function(){
  $("button").click(function(){
    $("p").fadeOut();
  });
});
Posted by: Guest on June-02-2020
0

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>
Posted by: Guest on August-18-2021
0

js fadeout

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());
Posted by: Guest on July-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language