<!DOCTYPE html> <html> <head> <script src="jquery.js"></script> <script> $(document).ready(function(){ $("#button1").mouseover(function(){ $(".div1").stop().animate({opacity:1},1000); $(".div2").stop().animate({opacity:1},1000); $(".div3").stop().animate({opacity:1},1000); }); $("#button1").mouseleave(function(){ $(".div1").stop().animate({opacity:0},1000); $(".div2").stop().animate({opacity:0},1000); $(".div3").stop().animate({opacity:0},1000); }); }); </script> </head> <body> <button id="button1">滑鼠放在這裡,使三個矩形淡入</button> <div class="div1" style="width:80px;height:80px;opacity:0;background-color:red;"></div> <br> <div class="div2" style="width:80px;height:80px;opacity:0;background-color:green;"></div> <br> <div class="div3" style="width:80px;height:80px;opacity:0;background-color:blue;"></div> </body> </html>
另外
function () { $(".div1").animate({ 'opacity': 0 },{ queue: false, duration: 1000 }); },
function () { $(".div1").animate({ 'opacity': 1 }, { queue: false, duration: 1000 }); }
也可以。