基于javascript實現(xiàn)右下角浮動廣告效果
更新時間:2016年01月08日 10:58:28 作者:leejersey
這篇文章主要介紹了基于javascript實現(xiàn)右下角浮動廣告效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了基于javascript實現(xiàn)右下角浮動廣告效果,供大家參考,具體內(nèi)容如下
效果圖:
具體代碼:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>右下角廣告代碼</title> <script type="text/javascript"> window.onload = getMsg; window.onresize = resizeDiv; window.onerror = function(){} function $(id) {return document.getElementById(id);} //短信提示使用(asilas添加) var divT,divL,divW,divH,docH,docW,docST,docSL,objTimer,i = 0; function getMsg() { try{ divT = parseInt($("eMeng").style.top,10); //層top位置 divL = parseInt($("eMeng").style.left,10); //層left位置 divH = parseInt($("eMeng").offsetHeight,10);//層寬 divW = parseInt($("eMeng").offsetWidth,10);//層高 docW = document.documentElement.clientWidth;//窗口寬 docH = document.documentElement.clientHeight;//窗口高 docST=document.documentElement.scrollTop; docSL=document.documentElement.scrollLeft; $("eMeng").style.top = parseInt(docST,10) + docH + 10+"px"; $("eMeng").style.left = parseInt(docSL,10) + docW - divW+"px"; $("eMeng").style.visibility="visible"; objTimer = setInterval("moveDiv()",10); } catch(e){} } function resizeDiv() { try{ divH = parseInt($("eMeng").offsetHeight,10); divW = parseInt($("eMeng").offsetWidth,10); docW = document.documentElement.clientWidth; docH = document.documentElement.clientHeight; $("eMeng").style.top = docH - divH + parseInt(document.documentElement.scrollTop,10)+"px"; $("eMeng").style.left = docW - divW + parseInt(document.documentElement.scrollLeft,10)+"px"; } catch(e){} } function moveDiv() { try{ if(parseInt($("eMeng").style.top,10) <= (docH - divH + parseInt(document.documentElement.scrollTop,10))) { window.clearInterval(objTimer) objTimer = setInterval("resizeDiv()",1) } divT = parseInt($("eMeng").style.top,10); $("eMeng").style.top = divT - 1+"px"; } catch(e){} } function closeDiv() { $('eMeng').style.visibility='hidden'; if(objTimer) window.clearInterval(objTimer) } </script> <div id="eMeng" style="z-index: 99999; visibility:hidden; left: 0px; width: 252px; position: absolute; top: 0px; height: 213px; background:url(http://image.5fad.com/5/img/ad_bg.gif)"> <div style=" height:28px"> <div style=" width:20px; height:20px; float:right; margin:5px 5px 0 0; cursor:pointer" onclick="closeDiv()"></div> </div> <div style="width:225px; height:164px; margin:0 auto;"><a target="_blank"><img src="http://image.5fad.com/5/ad/ad01.jpg" width="225" height="164" border="0" /></a></div> </div> </body> </html>
希望本文所述對大家學習javascript程序設(shè)計有所幫助。
相關(guān)文章
JS實現(xiàn)websocket長輪詢實時消息提示的效果
這篇文章主要介紹了JS實現(xiàn)websocket長輪詢實時消息提示的效果的相關(guān)資料,需要的朋友可以參考下2017-10-10Javascript異步表單提交,圖片上傳,兼容異步模擬ajax技術(shù)
使用Javascript異步表單提交,圖片上傳,兼容異步模擬ajax技術(shù),需要的朋友可以參考下。2010-05-05KnockoutJS 3.X API 第四章之表單textInput、hasFocus、checked綁定
這篇文章主要介紹了KnockoutJS 3.X API 第四章之表單textInput、hasFocus、checked綁定的相關(guān)資料,需要的朋友可以參考下2016-10-10