本文實例講述了jquery實現的Banner廣告收縮效果代碼。分享給大家供大家參考。具體如下:
這里演示一個Banner廣告收縮效果,點開后,網頁顯示大廣告,用鼠標點擊“關閉”后,廣告會收縮上去,此效果已在各大網站見到過,歡迎借鑒使用。
運行效果截圖如下:
在線演示地址如下:
http://demo.VeVB.COm/js/2015/jquery-banner-show-close-style-codes/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>一個Banner廣告收縮效果</title><style type="text/css">*{margin:0; padding:0;}/*為了方便 直接這樣重置了*/#main{margin:0 auto; width:960px;}#banner{display:none; margin:0 auto; width:960px; height:160px; background:url(images/banner.png) no-repeat; position:relative;}#close{display:block; width:50px; height:22px; text-align:center; line-height:22px; border:1px #ddd solid; background:#000; color:#fff; font-size:12px; float:right; cursor:pointer;}</style><script type="text/javascript" src="jquery-1.6.2.min.js"></script><script type="text/javascript">$(function(){$("#banner").slideDown();var Up=function(){$("#banner").slideUp(1500)}setTimeout(Up,3000);$("#close").click(function(){$("#banner").slideToggle(600,function(){if($("#banner").css("display") == "none"){$("#close").text("打開");}else{$("#close").text("關閉");}});});});</script></head><body><div id="main"><div id="banner"></div><span id="close">關閉</span></div></body></html>
希望本文所述對大家的jquery程序設計有所幫助。
新聞熱點
疑難解答