国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > JavaScript > 正文

js 右側(cè)浮動(dòng)層效果實(shí)現(xiàn)代碼(跟隨滾動(dòng))

2024-05-06 16:25:13
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

因?yàn)轫?xiàng)目上有這樣的需求,在網(wǎng)上也查了些東西,之前是想找個(gè)差不多類似的套用一下。后來(lái)發(fā)覺(jué)沒(méi)有合適的,因時(shí)間緊迫就自己動(dòng)手寫(xiě)了一個(gè)簡(jiǎn)單的 ,示例代碼如下 兼容火狐和IE7+

實(shí)現(xiàn)代碼一、

 

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

如果有時(shí)間的話 會(huì)稍作美化 然后加上動(dòng)畫(huà)效果 應(yīng)該就能算是個(gè)不錯(cuò)的浮動(dòng)隱藏層了。

方法二、

一、把以下代碼插入

標(biāo)簽中:

 

 
  1. <div id="FloatDIV" style="position: absolute;top: 0px; border-right: activeborder 1px solid; border-top: activeborder 1px solid; border-left: activeborder 1px solid; border-bottom: activeborder 1px solid;"
  2. 浮動(dòng)層示例:<br /> 
  3. <a target="_blank" href="tencent://message/?uin=101535223&Site=http://www.survivalescaperooms.com&Menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=1:101535223:3" alt="有事您說(shuō)話"></a> 
  4. </div> 

二、把以下代碼插到標(biāo)簽之后,設(shè)置MarginLeft、MarginTop、Width、Heigth四個(gè)變量的值

 

 
  1. <script language="javascript" type="text/javascript"
  2. var MarginLeft = 30; //浮動(dòng)層離瀏覽器右側(cè)的距離 
  3. var MarginTop = 50; //浮動(dòng)層離瀏覽器頂部的距離 
  4. var Width = 120; //浮動(dòng)層寬度 
  5. var Heigth= 45; //浮動(dòng)層高度 
  6.  
  7. //設(shè)置浮動(dòng)層寬、高 
  8. function Set() 
  9. document.getElementById("FloatDIV").style.width = Width; 
  10. document.getElementById("FloatDIV").style.height = Heigth; 
  11.  
  12. //實(shí)時(shí)設(shè)置浮動(dòng)層的位置 
  13. function Move() 
  14. document.getElementById("FloatDIV").style.top = document.documentElement.scrollTop + MarginTop; 
  15. document.getElementById("FloatDIV").style.left = document.documentElement.clientWidth - Width - MarginLeft; 
  16. setTimeout("Move();",100); 
  17.  
  18. Set(); 
  19. Move(); 
  20. </script> 


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JavaScript/Ajax教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 满城县| 宁明县| 苍梧县| 连平县| 隆回县| 宝兴县| 彝良县| 襄城县| 廊坊市| 海晏县| 新郑市| 哈尔滨市| 长泰县| 澜沧| 瑞金市| 乌拉特前旗| 原平市| 青阳县| 新野县| 广元市| 陇西县| 台北市| 介休市| 怀宁县| 满洲里市| 运城市| 洛宁县| 东乡族自治县| 温宿县| 卫辉市| 曲麻莱县| 城市| 阿拉尔市| 克什克腾旗| 清远市| 巴彦淖尔市| 芜湖市| 永福县| 济宁市| 崇州市| 临桂县|