Site logo

Archived topic

Why TOC scroll is not working on my posts?

18 replies · Started by linuxwolf on February 7, 2021

Viewing posts 1–15 of 19

Hi, I the table of content was working fine before but recently it has stopped working. I did everything, but it is not working. Could you please identify the issue? Also, check min.js from the Generatepress premium file if it relates. You can find the site shared for you.

I reinstalled the GP premium plugin, tried to change the min.js from the GP Premium-general-js-scroll min jas file but nothing worked. I use LuckyWP table of content.

Also, could you please confirm if there is an error since I had changed GP premium js from In the list on the right, choose: general > js > smooth-scroll.min.js

But changed it back to default later. I am afraid if I have broken anything.

Hi there,

the smooth-scroll JS is only required if you are using the GP Smooth Scroll option ( enabled in Customizer > General) ... but this is not required and should not be enabled for the ToC.

The issue i see when clicking on a link i can see a JS error being reported, some other event such as a Pop Up is blocking that script from running.

You will need to eliminate conflicts, first by disabling any cache/optimization plugins and then by disabling other plugins or custom functions to see if any are interfering.

Ok, got it.

Could you please confirm the code is correct or not?

window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;0<=--t&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),function(){if("function"==typeof window.CustomEvent)return;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}e.prototype=window.Event.prototype,window.CustomEvent=e}(),function(){for(var a=0,e=["ms","moz","webkit","o"],t=0;t<e.length&&!window.requestAnimationFrame;++t)window.requestAnimationFrame=window[e[t]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[t]+"CancelAnimationFrame"]||window[e[t]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e,t){var n=(new Date).getTime(),o=Math.max(0,16-(n-a)),i=window.setTimeout(function(){e(n+o)},o);return a=n+o,i}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){clearTimeout(e)})}(),function(e,t){"function"==typeof define&&define.amd?define([],function(){return t(e)}):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)}("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,function(A){"use strict";var C={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,clip:!0,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},q=function(){for(var n={},e=function(e){for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t])},t=0;t<arguments.length;t++)e(arguments[t]);return n},c=function(t){var n;try{n=decodeURIComponent(t)}catch(e){n=t}return n},s=function(e){"#"===e.charAt(0)&&(e=e.substr(1));for(var t,n,o=String(e),i=o.length,a=-1,r="",c=o.charCodeAt(0);++a<i;){if(0===(t=o.charCodeAt(a)))throw new InvalidCharacterError("Invalid character: the input contains U+0000.");1<=t&&t<=31||127==t||0===a&&48<=t&&t<=57||1===a&&48<=t&&t<=57&&45===c?r+="\\"+t.toString(16)+" ":r+=128<=t||45===t||95===t||48<=t&&t<=57||65<=t&&t<=90||97<=t&&t<=122?o.charAt(a):"\\"+o.charAt(a)}try{n=decodeURIComponent("#"+r)}catch(e){n="#"+r}return n},O=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},H=function(e){return e?(t=e,parseInt(A.getComputedStyle(t).height,10)+e.offsetTop):0;var t},I=function(e,t,n,o){if(t.emitEvents&&"function"==typeof A.CustomEvent){var i=new CustomEvent(e,{bubbles:!0,detail:{anchor:n,toggle:o}});document.dispatchEvent(i)}};return function(o,e){var v,i,w,b,t,S,E={};E.cancelScroll=function(e){cancelAnimationFrame(S),S=null,e||I("scrollCancel",v)},E.animateScroll=function(r,c,e){var s=q(v||C,e||{}),u="[object Number]"===Object.prototype.toString.call(r),t=u||!r.tagName?null:r;if(u||t){var l=A.pageYOffset;s.header&&!w&&(w=document.querySelector(s.header)),b||(b=H(w));var m,i,a,n,o,d=u?r:function(e,t,n,o){var i=0;if(e.offsetParent)for(;i+=e.offsetTop,e=e.offsetParent;);return i=Math.max(i-t-n,0),o&&(i=Math.min(i,O()-A.innerHeight)),i}(t,b,parseInt("function"==typeof s.offset?s.offset(r,c):s.offset,10),s.clip),f=d-l,h=O(),p=0,g=function(e,t){var n,o,i,a=A.pageYOffset;if(e==t||a==t||(l<t&&A.innerHeight+a)>=h)return E.cancelScroll(!0),o=t,i=u,0===(n=r)&&document.body.focus(),i||(n.focus(),document.activeElement!==n&&(n.setAttribute("tabindex","-1"),n.focus(),n.style.outline="none"),A.scrollTo(0,o)),I("scrollStop",s,r,c),!(S=m=null)},y=function(e){var t,n,o;m||(m=e),i=(p+=e-m)/parseInt(s.speed,10),a=l+f*(n=i=1<i?1:i,"easeInQuad"===(t=s).easing&&(o=n*n),"easeOutQuad"===t.easing&&(o=n*(2-n)),"easeInOutQuad"===t.easing&&(o=n<.5?2*n*n:(4-2*n)*n-1),"easeInCubic"===t.easing&&(o=n*n*n),"easeOutCubic"===t.easing&&(o=--n*n*n+1),"easeInOutCubic"===t.easing&&(o=n<.5?4*n*n*n:(n-1)*(2*n-2)*(2*n-2)+1),"easeInQuart"===t.easing&&(o=n*n*n*n),"easeOutQuart"===t.easing&&(o=1- --n*n*n*n),"easeInOutQuart"===t.easing&&(o=n<.5?8*n*n*n*n:1-8*--n*n*n*n),"easeInQuint"===t.easing&&(o=n*n*n*n*n),"easeOutQuint"===t.easing&&(o=1+--n*n*n*n*n),"easeInOutQuint"===t.easing&&(o=n<.5?16*n*n*n*n*n:1+16*--n*n*n*n*n),t.customEasing&&(o=t.customEasing(n)),o||n),A.scrollTo(0,Math.floor(a)),g(a,d)||(S=A.requestAnimationFrame(y),m=e)};0===A.pageYOffset&&A.scrollTo(0,0),n=r,o=s,u||history.pushState&&o.updateURL&&history.pushState({smoothScroll:JSON.stringify(o),anchor:n.id},document.title,n===document.documentElement?"#top":"#"+n.id),I("scrollStart",s,r,c),E.cancelScroll(!0),A.requestAnimationFrame(y)}};var n=function(e){if(!("matchMedia"in A&&A.matchMedia("(prefers-reduced-motion)").matches)&&0===e.button&&!e.metaKey&&!e.ctrlKey&&"closest"in e.target&&(i=e.target.closest(o))&&"a"===i.tagName.toLowerCase()&&!e.target.closest(v.ignore)&&i.hostname===A.location.hostname&&i.pathname===A.location.pathname&&/#/.test(i.href)){var t=s(c(i.hash)),n=v.topOnEmptyHash&&"#"===t?document.documentElement:document.querySelector(t);(n=n||"#top"!==t?n:document.documentElement)&&(e.preventDefault(),E.animateScroll(n,i))}},a=function(e){if(null!==history.state&&history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(v)&&history.state.anchor){var t=document.querySelector(s(c(history.state.anchor)));t&&E.animateScroll(t,null,{updateURL:!1})}},r=function(e){t||(t=setTimeout(function(){t=null,b=H(w)},66))};return E.destroy=function(){v&&(document.removeEventListener("click",n,!1),A.removeEventListener("resize",r,!1),A.removeEventListener("popstate",a,!1),E.cancelScroll(),S=t=b=w=i=v=null)},E.init=function(e){if(!("querySelector"in document&&"addEventListener"in A&&"requestAnimationFrame"in A&&"closest"in A.Element.prototype))throw"Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.";E.destroy(),v=q(C,e||{}),w=v.header?document.querySelector(v.header):null,b=H(w),document.addEventListener("click",n,!1),w&&A.addEventListener("resize",r,!1),v.updateURL&&v.popstate&&A.addEventListener("popstate",a,!1)},E.init(e),E}});var gpscroll=new SmoothScroll(smooth.elements.join(),{speed:smooth.duration,offset:function(e,t){var n=document.body,o=document.querySelector("#site-navigation"),i=document.querySelector("#sticky-navigation"),a=document.querySelector("#mobile-header"),r=document.querySelector(".menu-toggle"),c=0;return a&&(a.offsetWidth||a.offsetHeight||a.getClientRects().length)?n.classList.contains("mobile-header-sticky")&&(c+=a.clientHeight):r&&(r.offsetWidth||r.offsetHeight||r.getClientRects().length)?(n.classList.contains("both-sticky-menu")||n.classList.contains("mobile-sticky-menu"))&&(i?c+=i.clientHeight:o&&(c+=o.clientHeight)):(n.classList.contains("both-sticky-menu")||n.classList.contains("desktop-sticky-menu"))&&(i?c+=i.clientHeight:o&&(c+=o.clientHeight)),c}});

I use the smooth scroll from Customizer-->Genaral,
could you please confirm whether it is working or not?

I understand,

I just did copy-paste code, since the code I pasted didn't work, I pasted the default code back. (I had saved the default code in ms word)

Now, I have already done it. I need your view, if you can confirm that I didn't brake anything in GP premium and things working fine.

Hi there,

If you've reverted the code back to it's default then it should be working fine.

If it doesn't work you or you're not sure if you've properly reverted the files back to their default, you can simply reinstall GeneratePress so the files you've modified are overwritten by the installation.

As for making the smooth scroll work with your links, you can try David's suggestion.

Alternatively, you can disable the theme's smooth scroll and try my script here:
https://generatepress.com/forums/topic/how-to-increase-margin-of-smooth-scroll-sections/page/2/#post-1634951

Thank you for replay,
Could you please check it for me. If it's not working, I'll reinstall the GP premium plugin but I do not want to do it, this may break some features on my site.

If you want, I'll share my credentials. Please check it once.

Ah I see.

Can you try disabling JS combine on your Litespeed cache plugin and check if it works.

Some scripts are known to stop working when being aggregated/merged/combined with other scripts.

Hello Elvin,
I did everything and finally I found smooth scroll is active in both LuckyWP and Generatepress.

I disabled LuckyWP TOC and now touching elements from TOC table is working but smooth scrolling is not there.

Please check the link below.

Hello Devid, Thank you for replying again.

I can use the code as I am already using code snipt, but what is the use of built in smooth scrolling featur from General-->smooth scroll.

As, I have already turned on it and I am not sure weather it is working or not.

This archived topic is closed to new replies.