本文實例講述了jquery實現滑屏大圖定時收縮為小banner圖片的廣告代碼。分享給大家供大家參考。具體如下:
這是一款基于jQuery實現的JS廣告特效,滑屏大圖廣告定時收縮為小banner圖片廣告代碼,這種廣告在各大門戶網站現在還能看得到,剛打開網頁的時候可以看到滑下來的大圖片廣告,過一會,廣告自動縮小變成了一個banner橫幅廣告,并帶有關閉按鈕,可以關閉廣告,對于廣告來說,這個代碼挺實用。
運行效果截圖如下:
在線演示地址如下:
http://demo.VeVB.COm/js/2015/jquery-scroll-big-pic-cha-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>jQuery頂部大圖定時縮為小廣告可關閉代碼</title><style>body{ margin:0; padding:0;}img{ border:0}.root1200{ width:1200px; height:100px; margin:0 auto; overflow:visible}.wrapper em{ width:40px; height:15px; float:left; color:#FFF; font-size:12px; font-family:Verdana, Geneva, sans-serif;background:#333; margin:0 0 -20px 10px; padding:2px 5px 2px 10px; z-index:999; position:absolute; top:10px;}</style><script language="javascript" src="jquery-1.6.2.min.js"></script></head><body><script type="text/javascript">/** 寬窄屏切換* */var bigscreen = false;if ( screen.width>=1200 ) {bigscreen = true;var bodyTag = document.getElementsByTagName("body")[0],bodyClassName = bodyTag.getAttribute("className") || bodyTag.getAttribute("class");bodyClassName = bodyClassName ? bodyClassName+" " : "";bodyTag.className = bodyClassName+"root1200";}</script><div class="wrapper" id="snActive-wrap"> <em title="關閉廣告">Close</em><a target="_blank" name="redbaby_none_ggw_dt01" title="小圖" href="/"></a><a target="_blank" name="redbaby_none_ggw_dt01" title="大圖" href="/"></a></div><script type="text/javascript">~function (){var snActive = window.snActive = document.getElementById("snActive-wrap"),a = snActive.getElementsByTagName("a"),h = 0, w, imgSrc = [];if (bigscreen){w = 1190;imgSrc[0] = "images/1390124030537_1200.jpg";// 40imgSrc[1] = "images/1390124049068_1200.jpg";// 500} else {w = 990;imgSrc[0] = "images/1390124028186.jpg";// 40imgSrc[1] = "images/1390124043025.jpg";// 500}snActive.style.overflow = 'hidden';a[0].style.display = "none";a[0].innerHTML += '<img width="' + w + '" height="40" src="' + imgSrc[0] + '" style="display:block" />';if(a[1]){a[1].innerHTML += '<img width="' + w + '" height="500" src="' + imgSrc[1] + '" style="display:block" />';}}();//關閉通欄廣告var snActive = $(snActive),hideImg = snActive.find('a:hidden'),em = snActive.find("em");timeout = !1;if(hideImg[0]) {timeout = setTimeout(function(){snActive.animate({height:40},600,function(){hideImg.siblings('a:visible').hide();hideImg.show();em.show().live("click",function(){snActive.slideUp(300);});});}, 3000)}</script><div style="text-align:center;clear:both"></div></body></html>
希望本文所述對大家的jquery程序設計有所幫助。
新聞熱點
疑難解答