您现在的位置: 365建站网 > 365文章 > JS右下角广告窗口代码(可收缩、展开及关闭)

JS右下角广告窗口代码(可收缩、展开及关闭)

文章来源:365jz.com     点击数:401    更新时间:2017-08-10 15:25   参与评论

本文实例讲述了JS右下角广告窗口代码。分享给大家供大家参考。具体如下:

这是一款右下角窗口JS代码,完美的右下角,仿新浪博客的右个角弹出窗口,这款Javascript代码在兼容性和操作舒适度方面做的相当不错。调用了几张外部的图片,使用时自行下载吧。

运行效果截图如下:

在线演示地址如下:

https://www.365jz.com/daima/66/

具体代码如下:

</>code

  1. <!DOCTYPE html PUBLIC "-//W3C//h2D XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/h2D/xhtml1-transitional.h2d">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <style>
  7. * { padding: 0; margin: 0; }
  8. li { list-style: none; }
  9. body { background: #eee; }
  10. .float_layer { width: 300px; border: 1px solid #aaaaaa; display:none; background: #fff; }
  11. .float_layer h2 { height: 25px; line-height: 25px; padding-left: 10px; font-size: 14px; color: #333; background: url(images/title_bg.gif) repeat-x; border-bottom: 1px solid #aaaaaa; position: relative; }
  12. .float_layer .min { width: 21px; height: 20px; background: url(images/min.gif) no-repeat 0 bottom; position: absolute; top: 2px; right: 25px; }
  13. .float_layer .min:hover { background: url(images/min.gif) no-repeat 0 0; }
  14. .float_layer .max { width: 21px; height: 20px; background: url(images/max.gif) no-repeat 0 bottom; position: absolute; top: 2px; right: 25px; }
  15. .float_layer .max:hover { background: url(images/max.gif) no-repeat 0 0; }
  16. .float_layer .close { width: 21px; height: 20px; background: url(images/close.gif) no-repeat 0 bottom; position: absolute; top: 2px; right: 3px; }
  17. .float_layer .close:hover { background: url(images/close.gif) no-repeat 0 0; }
  18. .float_layer .content { height: 160px; overflow: hidden; font-size: 14px; line-height: 18px; color: #666; text-indent: 28px; }
  19. .float_layer .wrap { padding: 10px; }
  20. </style>
  21. <script type="text/javascript">
  22. function miaovAddEvent(oEle, sEventName, fnHandler)
  23. {
  24. if(oEle.attachEvent)
  25. {
  26. oEle.attachEvent('on'+sEventName, fnHandler);
  27. }
  28. else
  29. {
  30. oEle.addEventListener(sEventName, fnHandler, false);
  31. }
  32. }
  33. window.onload = function()
  34. {
  35. var oDiv=document.getElementById('miaov_float_layer');
  36. var oBtnMin=document.getElementById('btn_min');
  37. var oBtnClose=document.getElementById('btn_close');
  38. var oDivContent=oDiv.getElementsByTagName('div')[0];
  39. var iMaxHeight=0;
  40. var isIE6=window.navigator.userAgent.match(/MSIE 6/ig) && !window.navigator.userAgent.match(/MSIE 7|8/ig);
  41. oDiv.style.display='block';
  42. iMaxHeight=oDivContent.offsetHeight;
  43. if(isIE6)
  44. {
  45. oDiv.style.position='absolute';
  46. repositionAbsolute();
  47. miaovAddEvent(window, 'scroll', repositionAbsolute);
  48. miaovAddEvent(window, 'resize', repositionAbsolute);
  49. }
  50. else
  51. {
  52. oDiv.style.position='fixed';
  53. repositionFixed();
  54. miaovAddEvent(window, 'resize', repositionFixed);
  55. }
  56. oBtnMin.timer=null;
  57. oBtnMin.isMax=true;
  58. oBtnMin.onclick=function ()
  59. {
  60. startMove
  61. (
  62. oDivContent, (this.isMax=!this.isMax)?iMaxHeight:0,
  63. function ()
  64. {
  65. oBtnMin.className=oBtnMin.className=='min'?'max':'min';
  66. }
  67. );
  68. };
  69. oBtnClose.onclick=function ()
  70. {
  71. oDiv.style.display='none';
  72. };
  73. };
  74. function startMove(obj, iTarget, fnCallBackEnd)
  75. {
  76. if(obj.timer)
  77. {
  78. clearInterval(obj.timer);
  79. }
  80. obj.timer=setInterval
  81. (
  82. function ()
  83. {
  84. doMove(obj, iTarget, fnCallBackEnd);
  85. },30
  86. );
  87. }
  88. function doMove(obj, iTarget, fnCallBackEnd)
  89. {
  90. var iSpeed=(iTarget-obj.offsetHeight)/8;
  91. if(obj.offsetHeight==iTarget)
  92. {
  93. clearInterval(obj.timer);
  94. obj.timer=null;
  95. if(fnCallBackEnd)
  96. {
  97. fnCallBackEnd();
  98. }
  99. }
  100. else
  101. {
  102. iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
  103. obj.style.height=obj.offsetHeight+iSpeed+'px';
  104. ((window.navigator.userAgent.match(/MSIE 6/ig) && window.navigator.userAgent.match(/MSIE 6/ig).length==2)?repositionAbsolute:repositionFixed)()
  105. }
  106. }
  107. function repositionAbsolute()
  108. {
  109. var oDiv=document.getElementById('miaov_float_layer');
  110. var left=document.body.scrollLeft||document.documentElement.scrollLeft;
  111. var top=document.body.scrollTop||document.documentElement.scrollTop;
  112. var width=document.documentElement.clientWidth;
  113. var height=document.documentElement.clientHeight;
  114. oDiv.style.left=left+width-oDiv.offsetWidth+'px';
  115. oDiv.style.top=top+height-oDiv.offsetHeight+'px';
  116. }
  117. function repositionFixed()
  118. {
  119. var oDiv=document.getElementById('miaov_float_layer');
  120. var width=document.documentElement.clientWidth;
  121. var height=document.documentElement.clientHeight;
  122. oDiv.style.left=width-oDiv.offsetWidth+'px';
  123. oDiv.style.top=height-oDiv.offsetHeight+'px';
  124. }
  125. </script>
  126. </head>
  127. <body style="height: 2200px">
  128. <div class="float_layer" id="miaov_float_layer">
  129. <h2>
  130. <strong>这是标题</strong>
  131. <a id="btn_min" href="javascript:;" class="min"></a>
  132. <a id="btn_close" href="javascript:;" class="close"></a>
  133. </h2>
  134. <div class="content">
  135. <div class="wrap">
  136. 这里放置的是广告信息,你可以填入任何的广告内容,比如像这样:<strong>脚本之家是国内专业的网站建设资源、脚本编程学习类网站,提供asp、php、asp.net、javascript、jquery、vbscript、dos批处理、网页制作、网络编程、网站建设等编程资料</strong>脚本特效下载地址:<address>https://www.365jz.com/daima/</address>
  137. </div>
  138. </div>
  139. </div>
  140. </body>
  141. </html>

希望本文所述对大家的javascript程序设计有所帮助。

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (401人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号