GFT動態效果圖:
代碼:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="jquery.js"></script> <style> .blue{ height: 50px; width: 40px; background-color: blue; border-radius: 20px 20px 2px 2px; } .red{ height: 50px; width: 40px; background-color: red; border-radius: 20px 20px 2px 2px; } </style> </head> <body> <div class="blue"></div><br/> <input type="button" id="close" value="關閉" /> <input type="button" id="open" value="打開" /> <script type="text/javascript"> //定義定時器對象 var interval; //打開定時器 function open(){ if(interval != undefined){ alert("已經啓動!"); }else{ interval = setInterval(function(){ $("div").toggleClass("red"); },100); } } //關閉定時器 function close(){ clearInterval(interval); interval = undefined; } $(function(){ //關閉按鈕綁定點擊事件 $("#close").click(function(){ close(); }); //打開按鈕綁定點擊事件 $("#open").click(function(){ open(); }); }); </script> </body> </html>