Javascript fades out

I am new to JavaScript and I need a very simple script to slowly and slowly fade the image in a loop. Any help is appreciated.

+3
source share
2 answers

The easiest way is to use jQuery:

<img src="..." id="myImage">


<script type="text/javascript">
jQuery(function(){

   // Fade In
   $("#myImage").fadeIn();

   // Fade Out
   $("#myImage").fadeOut();

});
</script>

Documentation: http://api.jquery.com/fadeIn/

You can also change the attenuation time by passing a parameter

 // predefined slow (200ms)
 $("#myImage").fadeOut("slow");

 // predefined fast (600ms)
 $("#myImage").fadeOut("fast");

 // 1500 ms
 $("#myImage").fadeOut(1500);

Update loop creation:

function fadeIn()
{
   $(this).fadeIn( fadeOut );
}

function fadeOut()
{
   $(this).fadeOut( fadeIn );
}

fadeIn.call($("#myImage"));
+4
source

JQuery has a fadein function

$('#imgName').fadeIn('slow');
0
source

Source: https://habr.com/ru/post/1769750/


All Articles