浏览代码

采美百科顶部导航高亮bug修复

喻文俊 3 年之前
父节点
当前提交
d834614f28
共有 1 个文件被更改,包括 8 次插入12 次删除
  1. 8 12
      src/main/resources/static/js/encyclopedia/common.js

+ 8 - 12
src/main/resources/static/js/encyclopedia/common.js

@@ -320,23 +320,19 @@ function makeFloorList(options) {
 
 
 function activeNavbar(selector) {
-    var baseHref = window.location.href;
-    navbarIndex = localStorage.getItem('navbarIndex') || 0;
+    var pathname = window.location.pathname.replace(/(-\d+){0,}(.html$)/g, '') + '.html';
+    console.log(pathname);
     selector = $(selector);
-    selector.each(function (index, el) {
+    selector.each(function(index, el){
         $(el).removeClass('active');
-
-        if ($(el).find('a').length > 0) {
+        if($(el).find('a').length > 0){
             var href = $(el).find('a').attr('href');
-            href = href.split('?')[0].split('#')[0];
-
-            if (baseHref.indexOf(href) > -1) {
-                navbarIndex = index;
-                localStorage.setItem('navbarIndex', navbarIndex);
+            console.log(href);
+            if(pathname.endsWith(href)){
+                $(el).addClass('active');
             }
         }
-    });
-    selector.eq(navbarIndex).addClass('active');
+    })
 }
 
 /**