如何为JS id添加淡入淡出效果

How to add fade effect to a JS id

本文关键字:淡入 淡出 添加 id JS      更新时间:2023-09-26

我有一个图像和一个按钮,每当我按下按钮时,图像就会消失。所以我想用渐变效果来制作它。类似这样的东西:

#hide{-webkit-transition: all 1s ease-in-out;}

以下是演示:http://jsfiddle.net/5wBuV/4/

在jQuery中,您所要做的就是:

$("#hide").fadeOut("slow"); //or fast, or specific speed in milliseconds
//you can even throw a callback function if you need to

或者你可以保留你的javascript:

document.getElementById("hide").style.visibility = "hidden"; //or display = "none";

http://jsfiddle.net/5wBuV/5/更新了你的小提琴

使用一些JS:$('#hide').fadeOut('slow');

如果您想要更高级的方式,请参阅Jquery动画中的更多内容

对于动画效果,您可以在谷歌上搜索"jquery easing"

使用jQuery fadeOut():

 $("#clickedButton").click( function() {
     $('#hide').fadeOut('1000');
});

FIDDLE