js廣告彈窗

來源:互聯網
上載者:User

標籤:

    生活中我們經常遇到一些煩人的廣告頁面,比方說彈窗,懸浮等等各種廣告。有的同事甚至都下一個屏蔽廣告外掛程式到瀏覽器上。這樣就防止了廣告的幹擾。

但是我們學前端的必須是要知道廣告彈窗這個做的過程,甚至是它的原理。

下面是我自己做的一個小案例,希望能夠協助到大家。當然,有不妥當的地方,還望多多指教。謝謝!

HTML代碼部分:

1 <div id="popup">2         <p>廣告文字 廣告文字 廣告文字 </p>3         <span id="dele">X</span>4     </div>

CSS代碼部分:

 1 <style type="text/css"> 2         *{margin: 0;padding: 0;} 3         html{width: 100%;} 4         body{width: 100%;position: relative;} 5         #popup{width: 310px;height: 144px; 6             background-color: yellowgreen;    position: fixed; 7             left: 50%;top: 50%;margin-left: -155px; 8             margin-top: -72px;display: none;} 9         p{text-align: center;  line-height: 144px;}10         span{11             position: absolute;12             top: 0;13             right: 0;14             width: 20px;15             height: 20px;16             background-color: red;17             text-align: center;18             cursor: pointer;19             20         }21     </style>

JS代碼部分:

 1 <script type="text/javascript"> 2         var Pop = document.getElementById("popup"); 3         var Dele = document.getElementById("dele"); 4         window.onload = function(){ 5  6             Pop.style.display = "block"; 7  8             Dele.onclick = function(){ 9                 Pop.style.display = "none";10 11                 setTimeout(function(){12                     Pop.style.display = "block";13                 },3000)14             }15         }16     </script>

最終效果如所示:

 

js廣告彈窗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.