I'm doing a small script which the element should disappear for only 2 seconds and then return to appear alone, I leave the link here Fiddle
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('img').click(function() {
$(this).fadeOut();
setTimeout(function() {
$(this).fadeIn();
}, 1000);
//$(this).toggle();
});
});
</script>
im trying using fade and set time but it not works
The this
on $(this).fadeIn();
does not point to the image anymore.
Try this:
$(document).ready(function() {
$('img').click(function() {
var img = this; /* Store it on variable img */
$(img).fadeOut();
setTimeout(function() {
$(img).fadeIn(); /* Can access variable img here */
}, 1000);
//$(this).toggle();
});
});
Fiddle: https://jsfiddle.net/7rfypomx/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With