Просмотр исходного кода

destroy slim scroll if not needed

Yuki Takei 6 лет назад
Родитель
Сommit
fa736fc6b6
1 измененных файлов с 11 добавлено и 8 удалено
  1. 11 8
      src/client/js/components/TableOfContents.jsx

+ 11 - 8
src/client/js/components/TableOfContents.jsx

@@ -71,17 +71,20 @@ class TableOfContents extends React.Component {
     const tocContentElem = document.querySelector('.revision-toc .markdownIt-TOC');
     const tocContentElem = document.querySelector('.revision-toc .markdownIt-TOC');
 
 
     // window height - revisionTocTop - .system-version height
     // window height - revisionTocTop - .system-version height
-    let h = window.innerHeight - revisionTocTop - 20;
+    const viewHeight = window.innerHeight - revisionTocTop - 20;
 
 
     const tocContentHeight = tocContentElem.getBoundingClientRect().height + 15; // add margin
     const tocContentHeight = tocContentElem.getBoundingClientRect().height + 15; // add margin
 
 
-    h = Math.min(h, tocContentHeight);
-
-    $('#revision-toc-content').slimScroll({
-      railVisible: true,
-      position: 'right',
-      height: h,
-    });
+    if (viewHeight < tocContentHeight) {
+      $('#revision-toc-content').slimScroll({
+        railVisible: true,
+        position: 'right',
+        height: viewHeight,
+      });
+    }
+    else {
+      $('#revision-toc-content').slimScroll({ destroy: true });
+    }
   }
   }
 
 
   render() {
   render() {