找回密码
 立即注册
搜索

途迹耕耘

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

GMT+8, 2025-12-22 07:26 , Processed in 0.228326 second(s), 13 queries .

[DZ教程] discuz 门户页面支持导航顶部固定

[复制链接]
bdk 发表于 2020-5-2 06:50:02 | 显示全部楼层 |阅读模式
网上的方法,在需要顶部固定的页面加一句代码:
  1. <!--{if empty($_G['setting']['disfixednv_forumindex']) }--><script>fixed_top_nv();</script><!--{/if}-->
复制代码
亲测此方法成功过,也失败过。
如果不管用,也可以使用下面代码:

  1. <style type="text/css">
  2. .floatnv{position:fixed;_position:absolute;top:0px;z-index:999;width:100%;}
  3. </style>
  4. <script language="javascript" type="text/javascript">
  5.     (function() {
  6.         var oDiv = document.getElementById("nv");
  7.         var H = 0, iE6;
  8.         var Y = oDiv;
  9.         while (Y) {
  10.             H += Y.offsetTop;
  11.             Y = Y.offsetParent;
  12.         };
  13.         iE6 = window.ActiveXObject && !window.XMLHttpRequest;
  14.         if (!iE6) {
  15.             window.onscroll = function() {
  16.                 var s = document.body.scrollTop || document.documentElement.scrollTop;
  17.                 if (s > H) {
  18.                     oDiv.className = "floatnv";
  19.                     if (iE6) {
  20.                         oDiv.style.top = (s - H) + "px";
  21.                     }
  22.                 } else {
  23.                     oDiv.className = "";
  24.                 }
  25.             }
  26.         }
  27.     })();
  28. </script>
复制代码
document.getElementById("nv");对应的是id="nv"的元素。