zhangxc 4 tahun lalu
induk
melakukan
1dc254415d
2 mengubah file dengan 17 tambahan dan 11 penghapusan
  1. 3 3
      src/css/staticSearch.css
  2. 14 8
      src/js/information.js

+ 3 - 3
src/css/staticSearch.css

@@ -18,8 +18,8 @@ html{
 .staticSearchT {
     position: relative;
     padding-right: 80px;
-    padding-bottom: 15px;
-    padding-top: 30px;
+    padding-bottom: 10px;
+    padding-top: 10px;
 }
 .container .ipt {
     width: 100%;
@@ -40,7 +40,7 @@ html{
 .container .staticSearchT button {
     position: absolute;
     right: 0;
-    top: 30px;
+    top: 10px;
     width: 80px;
     height: 34px;
     line-height: 34px;

+ 14 - 8
src/js/information.js

@@ -72,9 +72,9 @@ function renderContent(list, contentWrapClassName){
     for (var i = 0; i < list.length; i++) {
         var item = list[i];
         item.content = item.content&&item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
-        anchors = '<li><i></i><a href="#' + item.title +
+        anchors = '<li><i></i><a href="#' + contentWrapClassName+i +
           '">' + item.title + '</a></li><li class="anchor-line"></li>';
-        str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + item.title +
+        str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + contentWrapClassName+i +
           '">'
         if (getUrlArgObject('type') == 8) {
           str += '【' + item.title + '】'
@@ -89,18 +89,19 @@ function renderContent(list, contentWrapClassName){
     }
 
     function addScrollEvent() {
-      var scrollTop = $('.infos').scrollTop()
+      var scrollTop = $(`.${contentWrapClassName} .infos`).scrollTop()
+
       var divHeight = 0;
       for (var i = 0; i < list.length; i++) {
-        divHeight = divHeight + parseInt($('#' + list[i].title).css('height')) + parseInt($('#' + list[i].title).parent().next().css('height')) + 20
+        divHeight = divHeight + parseInt($('#'+contentWrapClassName+i).css('height')) + parseInt($('#'+contentWrapClassName+i).parent().next().css('height')) + 20
         if (divHeight > scrollTop) {
           var anchor = 2 * i;
-          $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
+          $(`.${contentWrapClassName} .anchors ul`).children().eq(anchor).addClass('active').siblings().removeClass('active');
           return;
         }
       }
     }
-    $(".infos").scroll(throttle(addScrollEvent, 200));
+    $(`.${contentWrapClassName} .infos`).scroll(throttle(addScrollEvent, 200));
     addLinkClickEvent(contentWrapClassName);
     adjustHeight();
     adjustWidth()
@@ -111,8 +112,13 @@ function renderContent(list, contentWrapClassName){
 function addLinkClickEvent(contentWrapClassName) {
   $(`.${contentWrapClassName} .anchors li:first`).addClass("active");
   $(`.${contentWrapClassName}  .anchors li>a`).on("click", function () {
-    $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
-    $(this).parent().addClass("active");
+
+    const that = this
+    setTimeout(function(){
+      $(`.${contentWrapClassName} .anchors .active`).removeClass('active');
+      $(that).parent().addClass("active");
+    },20)
+
   });
 }