当前位置:Gxlcms > JavaScript > js实现关闭悬浮框广告特效详解

js实现关闭悬浮框广告特效详解

时间:2021-07-01 10:21:17 帮助过:11人阅读

注意不能直接用close()命名关闭广告函数,避免冲突。

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  4. <title>无标题文档</title><style type="text/css">
  5. #apDiv1 {position: absolute;left: 251px;top: 51px;width: 529px;height: 210px;z-index: 2;background-color: #0000FF;}
  6. #closebt {position: absolute;top: 0;right: 0;background: red;}
  7. #apDiv2 {position: absolute;left: 128px;top: 381px;width: 912px;height: 18663px;z-index: -1;background-color: #FF0000;}-->
  8. </style><script>var xx = 0;function init() {//获取元素的top值 xx = document.getElementById("apDiv1").offsetTop;
  9. }function aa() {if (document.body.scrollTop)
  10. {//兼容谷歌
  11. document.getElementById("apDiv1").style.top = xx + document.body.scrollTop + "px";
  12. } else {//兼容ie,火狐
  13. document.getElementById("apDiv1").style.top = xx + document.documentElement.scrollTop + "px";
  14. }
  15. }
  16. window.onscroll = aa;function closetext() {
  17. document.getElementById("closebt").style.display="none";
  18. document.getElementById("apDiv1").style.display="none";
  19. }</script>
  20. </head>
  21. <body onload="init()">
  22. <div id="apDiv1"><span id="closebt"><a href="#" onclick="closetext()">可关闭</a>
  23. </span></div><div id="apDiv2">
  24. </div>
  25. </body>
  26. </html>

以上就是js实现关闭悬浮框广告特效详解的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行