]> BookStack Code Mirror - bookstack/commitdiff
Tried to make chapter toggles a little smoother in FF 1009/head
authorDan Brown <redacted>
Sat, 22 Sep 2018 15:36:35 +0000 (16:36 +0100)
committerDan Brown <redacted>
Sat, 22 Sep 2018 15:36:35 +0000 (16:36 +0100)
resources/assets/js/components/chapter-toggle.js
resources/assets/sass/_lists.scss

index e3a542ea4cdaf4e9994fce1788473e9db4cd526c..420b8d721c4e279ac51dffba4816c4e71e6e24fc 100644 (file)
@@ -8,52 +8,56 @@ class ChapterToggle {
     }
 
     open() {
-        let list = this.elem.parentNode.querySelector('.inset-list');
+        const list = this.elem.parentNode.querySelector('.inset-list');
 
         this.elem.classList.add('open');
         list.style.display = 'block';
-        list.style.height = '';
-        let height = list.getBoundingClientRect().height;
-        list.style.height = '0px';
+        list.style.maxHeight = '';
+        const maxHeight = list.getBoundingClientRect().height + 10;
+        list.style.maxHeight = '0px';
         list.style.overflow = 'hidden';
-        list.style.transition = 'height ease-in-out 240ms';
+        list.style.transition = 'max-height ease-in-out 240ms';
 
         let transitionEndBound = onTransitionEnd.bind(this);
         function onTransitionEnd() {
             list.style.overflow = '';
-            list.style.height = '';
+            list.style.maxHeight = '';
             list.style.transition = '';
             list.style.display = `block`;
             list.removeEventListener('transitionend', transitionEndBound);
         }
 
         setTimeout(() => {
-            list.style.height = `${height}px`;
-            list.addEventListener('transitionend', transitionEndBound)
+            requestAnimationFrame(() => {
+                list.style.maxHeight = `${maxHeight}px`;
+                list.addEventListener('transitionend', transitionEndBound)
+            });
         }, 1);
     }
 
     close() {
-        let list = this.elem.parentNode.querySelector('.inset-list');
+        const list = this.elem.parentNode.querySelector('.inset-list');
 
-        this.elem.classList.remove('open');
         list.style.display =  'block';
-        list.style.height = list.getBoundingClientRect().height + 'px';
+        this.elem.classList.remove('open');
+        list.style.maxHeight = list.getBoundingClientRect().height + 'px';
         list.style.overflow = 'hidden';
-        list.style.transition = 'height ease-in-out 240ms';
+        list.style.transition = 'max-height ease-in-out 240ms';
 
-        let transitionEndBound = onTransitionEnd.bind(this);
+        const transitionEndBound = onTransitionEnd.bind(this);
         function onTransitionEnd() {
             list.style.overflow = '';
-            list.style.height = '';
+            list.style.maxHeight = '';
             list.style.transition = '';
             list.style.display =  'none';
             list.removeEventListener('transitionend', transitionEndBound);
         }
 
         setTimeout(() => {
-            list.style.height = `0px`;
-            list.addEventListener('transitionend', transitionEndBound)
+            requestAnimationFrame(() => {
+                list.style.maxHeight = `0px`;
+                list.addEventListener('transitionend', transitionEndBound)
+            });
         }, 1);
     }
 
index 0bf6be4c358e678fd3be5415ae397f4d9fed0204..a1cf1f3d56b2cdfc01901081d2151f80eb590664 100644 (file)
     display: none;
     padding-left: 0;
   }
-  .sub-menu.open {
+  [chapter-toggle].open + .sub-menu {
     display: block;
   }
 }