您可以通过结合 JS 和 CSS3 过渡来做到这一点。
http://jsfiddle.net/hQLQQ/1/
CSS:
#regform {
-webkit-transition:opacity 300ms;
-moz-transition:opacity 300ms;
-o-transition:opacity 300ms;
-ms-transition:opacity 300ms;
}
JS:
var toggle = function(elm){
// check if style property is defined, then read .display, or assume it's "block"
var y=elm.style ? elm.style.display : '';
if (!y || y == 'block'){
// change the opacity. CSS will handle the animation.
elm.style.opacity='0';
// change the display to "none" after a delay.
setTimeout( function(){ elm.style.display = 'none'; }, 300 );
}
else {
// change diplay to block. the element is still transparent.
elm.style.display='block';
// set the opacity to 1, CSS will animate it.
// small delay because some browsers won't properly
// animate when changing "display" at the same moment.
setTimeout( function(){ elm.style.opacity = '1'; }, 10 );
}
}