js 跟随滚动的右侧浮动层

  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
  2  
  3 <html>
  4  <head>
  5      <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  6      <title>无标题文档</title>
  7      <!--***********开始*************-->
  8  
  9     <script type="text/javascript">
 10          //<![CDATA[  
 11         var tips; var theTop = 200/*这是默认高度,越大越往下*/; var old = theTop;
 12          function initFloatTips() {
 13              tips = document.getElementById('floatTips');
 14              moveTips();
 15          };
 16          function moveTips() {
 17              var tt = 50;
 18              if (window.innerHeight) {
 19                  pos = window.pageYOffset
 20              }
 21              else if (document.documentElement && document.documentElement.scrollTop) {
 22                  pos = document.documentElement.scrollTop
 23              }
 24              else if (document.body) {
 25                  pos = document.body.scrollTop;
 26              }
 27              pos = pos - tips.offsetTop + theTop;
 28              pos = tips.offsetTop + pos / 10;
 29              if (pos < theTop) pos = theTop;
 30              if (pos != old) {
 31                  tips.style.top = pos + "px";
 32                  tt = 10;
 33              }
 34              old = pos;
 35              setTimeout(moveTips, tt);
 36          }
 37  
 38         //!]]>  
 39     </script>
 40  
 41     <style type="text/css">
 42          .floatTips
 43          {
 44              position: absolute;
 45              border: solid 1px #777;
 46              padding: 3px;
 47              top: 250px;
 48              right: 5px;
 49              width: 30px;
 50              height: 300px;
 51              background: #cccccc;
 52              color: white;
 53          }
 54          .showDiv
 55          {
 56              position: absolute;
 57              border: solid 1px #777;
 58              padding: 3px;
 59              top: 250px;
 60              right: 5px;
 61              width: 300px;
 62              height: 300px;
 63              background: #cccccc;
 64              color: white;
 65          }
 66      </style>
 67  
 68     <script type="text/javascript">
 69          function FunOnmouseUp() {
 70              var objFloatTips = $("floatTips");
 71              var objActivityContext = $("activityContext");
 72              objFloatTips.className = "showDiv";
 73              objActivityContext.style.display = "";
 74          }
 75          function FunMouseOut() {
 76              var objFloatTips = $("floatTips");
 77              var objActivityContext = $("activityContext");
 78              objFloatTips.className = "floatTips";
 79              objActivityContext.style.display = "none";
 80          }
 81  
 82         function $(objID) {
 83              return document.getElementById(objID);
 84          }
 85      </script>
 86  
 87 </head>
 88  <body onload="initFloatTips()">
 89      <div id="floatTips" onmouseover="FunOnmouseUp()" onmouseout="FunMouseOut()" class="floatTips">
 90          最新的活动
 91          <div id="activityContext" style="display: none">
 92              显示最新的活动
 93          </div>
 94      </div>
 95      <!--**********结束***************-->
 96      <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#F7F7F7">
 97          <tr>
 98              <td height="2101">
 99              </td>
100          </tr>
101      </table>
102  </body>
103  </html>

 

转载于:https://www.cnblogs.com/zhangchuan/archive/2013/04/12/3016638.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值