瀏覽代碼

prevent toTop button from opening menu

Riccardo Balbo 4 年之前
父節點
當前提交
4b08868e76
共有 1 個文件被更改,包括 8 次插入5 次删除
  1. 8 5
      static/js/utils.js

+ 8 - 5
static/js/utils.js

@@ -80,7 +80,6 @@ function lazyLoad(parent) {
 
 
 let floatingHeader = null;
-let visibleDisplay = null;
 const updateFloatingHeader = () => {
     const header = document.querySelector("body > header");
     const siteTitle = document.querySelector("#siteTitle");
@@ -88,19 +87,23 @@ const updateFloatingHeader = () => {
         console.info("Create floating header!");
         floatingHeader = header.cloneNode(true);
         floatingHeader.classList.add("floating");
-        const toTopBtn = floatingHeader.querySelector(".toggleNavOnPortraitButton");
+        let toTopBtn = floatingHeader.querySelector(".toggleNavOnPortraitButton");
         if (toTopBtn) {
+            let newTopBtn=toTopBtn.cloneNode(true);
+            toTopBtn.parentNode.replaceChild(newTopBtn,toTopBtn);
+            toTopBtn=newTopBtn;
+            toTopBtn.removeAttribute("toggle");
             toTopBtn.setAttribute("class", "toggleNavOnPortraitButton fas fa-angle-up");
             toTopBtn.setAttribute("title", "To top");
-            toTopBtn.onclick = () => {
+            toTopBtn.addEventListener("click",(ev) => {
                 window.scrollTo({
                     top: 0,
                     left: 0,
                     behavior: 'smooth'
                 });
-            }
+           
+            });
         }
-        visibleDisplay = floatingHeader.style.display;
         document.body.append(floatingHeader);
     }
     if (!isInViewport(siteTitle)) {