pages/assets/js/vanilla-back-to-top.min.js
Abhilesh Dhawanjewar 9e59ab8d72
Fix: Add back-to-top button (#2433)
Fixes #2425 

PR #2427 adds a back-to-top button, however the button overlaps with the
footer when `footer_fixed: false` and [has inadequate
spacing](https://github.com/alshedivat/al-folio/issues/2425#issuecomment-2121670658)
with `footer_fixed: true`

Changes in this PR:
- Fix positioning of button on fixed and sticky footer layouts 
- Add option to disable back-to-top button by setting `back_to_top:
false` in `_config.yml`
- Add button transparency to avoid button blocking content view
- Reduce size of button

Demo - 

| Device | Fixed footer | Sticky footer |
| :-----------: | :-------------: | :-----------: |
| Mobile |
![fixed_footer_mobile](https://github.com/alshedivat/al-folio/assets/2447878/2e17be04-1fa7-40c5-b691-829e92055367)
|
![sticky_footer_mobile](https://github.com/alshedivat/al-folio/assets/2447878/f5567e43-e6fe-442d-9a7f-99e0577e220b)
|
| Desktop |
![fixed_footer_desktop](https://github.com/alshedivat/al-folio/assets/2447878/fc755839-841a-4e6b-b249-2c75bc552ad8)
|
![sticky_footer_desktop](https://github.com/alshedivat/al-folio/assets/2447878/ef9a4c99-ce4c-4ac3-8fbb-207af9be245a)
|

Miscellaneous change - Added personal website under `Academics` to
`README.md`
2024-05-24 15:58:55 -03:00

1 line
2.9 KiB
JavaScript

"use strict";function addBackToTop(){function o(){t()>=z?R&&(D.className="",R=!1):R||(D.className="hidden",R=!0)}function t(){return E.scrollTop||A&&document.documentElement.scrollTop||0}function e(o){E.scrollTop=o,A&&(document.documentElement.scrollTop=o)}var n,i,d,r,c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=c.backgroundColor,s=void 0===a?"#000":a,l=c.cornerOffset,u=void 0===l?20:l,m=c.diameter,p=void 0===m?56:m,h=c.ease,b=void 0===h?function(o){return.5*(1-Math.cos(Math.PI*o))}:h,v=c.id,f=void 0===v?"back-to-top":v,x=c.innerHTML,g=void 0===x?'<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path></svg>':x,w=c.onClickScrollTo,y=void 0===w?0:w,k=c.scrollContainer,E=void 0===k?document.body:k,T=c.scrollDuration,C=void 0===T?100:T,M=c.showWhenScrollTopIs,z=void 0===M?1:M,L=c.size,B=void 0===L?p:L,H=c.textColor,I=void 0===H?"#fff":H,N=c.zIndex,S=void 0===N?1:N,q=E===document.body,A=q&&document.documentElement;n=Math.round(.35*B),i=Math.round(.2*B),d="#"+f+"{background:"+s+";-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%;bottom:"+u+"px;-webkit-box-shadow:0 2px 5px 0 rgba(0,0,0,.26);-moz-box-shadow:0 2px 5px 0 rgba(0,0,0,.26);box-shadow:0 2px 5px 0 rgba(0,0,0,.26);color:"+I+";cursor:pointer;display:block;height:"+B+"px;opacity:1;outline:0;position:fixed;right:"+u+"px;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-transition:bottom .2s,opacity .2s;-o-transition:bottom .2s,opacity .2s;-moz-transition:bottom .2s,opacity .2s;transition:bottom .2s,opacity .2s;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:"+B+"px;z-index:"+S+"}#"+f+" svg{display:block;fill:currentColor;height:"+n+"px;margin:"+i+"px auto 0;width:"+n+"px}#"+f+".hidden{bottom:-"+B+"px;opacity:0}",(r=document.createElement("style")).appendChild(document.createTextNode(d)),document.head.insertAdjacentElement("afterbegin",r);var D=function(){var o=document.createElement("div");return o.id=f,o.className="hidden",o.innerHTML=g,o.addEventListener("click",function(o){o.preventDefault(),function(){var o="function"==typeof y?y():y,n=window,i=n.performance,d=n.requestAnimationFrame;if(C<=0||void 0===i||void 0===d)return e(o);var r=i.now(),c=t(),a=c-o;d(function o(t){var n=Math.min((t-r)/C,1);e(c-Math.round(b(n)*a)),n<1&&d(o)})}()}),document.body.appendChild(o),o}(),R=!0;(q?window:E).addEventListener("scroll",o),o()}window.addEventListener("load",function(){var o=document.getElementById("back-to-top"),t=document.querySelector(".sticky-bottom"),e=document.querySelector(".fixed-bottom");o&&window.addEventListener("scroll",function(){if(t){var n=t.getBoundingClientRect();window.scrollY+window.innerHeight>document.body.scrollHeight-n.height?(o.style.position="fixed",o.style.bottom=n.height+15+"px"):(o.style.position="fixed",o.style.bottom="15px")}if(e){var i=e.getBoundingClientRect();o.style.position="fixed",o.style.bottom=i.height+15+"px"}})});