1. 程式人生 > >javaEE (五)javaweb_jQuery (1) jQ重寫廣告彈出

javaEE (五)javaweb_jQuery (1) jQ重寫廣告彈出

Date:2018/11/18

重寫廣告彈出
原始碼:

1、書寫定時廣告圖片的定時操作  time = setInterval("showAd()",3000);  
2、書寫顯示廣告的函式  function showAd()
3、獲取廣告圖片,並顯示   $("#img2").show(4000);   
4、清除顯示圖片的定時操作 clearInterval(time);
5、設定隱藏圖片的定時操作  setInterval("hiddenAd()",3000);   
6、書寫隱藏廣告的函式  function hiddenAd()
7、清除隱藏圖片的定時操作 clearInterval(time);

注:clearInterval
(time);是為了讓圖片只彈出一次,清除定時操作, <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>首頁</title> <style> #father{ border: 0px solid red; width: 1300px; height: 2170px; margin: auto; } /*#logo{ border: 0px solid black; width: 1300px; height: 50px; }*/
.top{ border: 0px solid blue; width: 431px; height: 50px; float: left; } #top{ padding-top: 12px; height: 38px; } #menu{ border: 0px solid red; width: 1300px; height: 50px; background-color: black; margin-bottom: 10px; } ul li{ display: inline;
color: white; } #clear{ clear: both; } #product{ border: 0px solid red; width: 1300px; height: 558px; } #product_top{ border: 0px solid blue; width: 100%; height: 45px; padding-top: 8px; } #product_bottom{ border: 0px solid green; width: 100%; height: 500px; } #product_bottom_left{ border: 0px solid red; width: 200px; height: 500px; float: left; } #product_bottom_right{ border: 0px solid blue; width: 1094px; height: 500px; float: left; } #big{ border: 0px solid red; width: 544px; height: 248px; float: left; } .small{ border: 0px solid blue; width: 180px; height: 248px; float: left; /*讓裡面的內容居中*/ text-align: center; } #bottom{ text-align: center; } a{ text-decoration: none; } </style> <script type="text/javascript" src="../js/jquery-1.8.3.js" ></script> <script> $(function(){ time = setInterval("showAd()",3000); }); function showAd(){ $("#img2").(4000); clearInterval(time); time = setInterval("hiddenAd()",1000); } function hiddenAd(){ $("#img2").hide(4000); //4秒 clearInterval(time); } </script> </head> <body onload="init()"> <div id="father"> <!--定時彈出廣告圖片位置--> <img src="../img/f001a62f-a49d-4a4d-b56f-2b6908a0002c_g.jpg" width="100%" style="display: none" id="img2"/> <!--1.logo部分--> <div id="logo"> <div class="top"> <img src="../img/logo2.png" height="46px"/> </div> <div class="top"> <img src="../img/header.png" height="46px" /> </div> <div class="top" id="top"> <a href="#">登入</a> <a href="#">註冊</a> <a href="#">購物車</a> </div> </div> <div id="clear"> </div> <!--2.導航欄部分--> <div id="menu"> <ul> <a href="#"><li style="font-size: 20px;">首頁</li></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="#"><li>手機數碼</li></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="#"><li>家用電器</li></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="#"><li>鞋靴箱包</li></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="#"><li>孕嬰保健</li></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="#"><li>奢侈品</li></a> </ul> </div> <!--3.輪播圖部分--> <div id=""> <img src="../img/1.jpg" width="100%" id="img1"/> </div> <!--4.最新商品--> <div id="product"> <div id="product_top"> &nbsp;&nbsp;&nbsp; <span style="font-size: 25px;padding-top: 8px;">最新商品</span>&nbsp;&nbsp;&nbsp; <img src="../img/title2.jpg" /> </div> <div id="product_bottom"> <div id="product_bottom_left"> <img src="../img/big01.jpg" width="100%" height="100%"/> </div> <div id="product_bottom_right"> <div id="big"> <a href="#"><img src="../img/middle01.jpg" width="100%" height="100%"/></a> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> </div> </div> </div> <!--5.廣告圖片--> <div id=""> <img src="../img/ad.jpg" width="100%" /> </div> <!--6.熱門商品--> <div id="product"> <div id="product_top"> &nbsp;&nbsp;&nbsp; <span style="font-size: 25px;padding-top: 8px;">熱門商品</span>&nbsp;&nbsp;&nbsp; <img src="../img/title2.jpg" /> </div> <div id="product_bottom"> <div id="product_bottom_left"> <img src="../img/big01.jpg" width="100%" height="100%"/> </div> <div id="product_bottom_right"> <div id="big"> <a href="#"><img src="../img/middle01.jpg" width="100%" height="100%"/></a> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> <div class="small"> <img src="../img/small03.jpg" /> <a href="#"><p style="color: gray;">電燉鍋</p></a> <p style="color: red;">¥399</p> </div> </div> </div> </div> <!--7.廣告圖片--> <div id=""> <img src="../img/footer.jpg" width="100%"/> </div> <!--8.友情連結和版權資訊--> <div id="bottom"> <a href="#">關於我們</a> <a href="#">聯絡我們</a> <a href="#">招賢納士</a> <a href="#">法律宣告</a> <a href="#">友情連結</a> <a href="#">支付方式</a> <a href="#">配送方式</a> <a href="#">服務宣告<