vanilla-back-to-top
Advanced tools
Comparing version 2.0.1 to 3.0.0
@@ -1,1 +0,1 @@ | ||
function addBackToTop({id:e="back-to-top",scrollContainer:t=document.documentElement,showWhenScrollTopIs:n=300,onClickScrollTo:o=0,innerElement:c=document.createTextNode("Up"),size:i=50,fontSize:d=14,cornerOffset:r=20,backgroundColor:a="#000",textColor:l="#fff",zIndex:s=1}){!function(){const t=`#${e}{bottom:${r}px;opacity:1;position:fixed;right:${r}px;transition:bottom .2s,opacity .2s;z-index:${s};}#${e}.hidden{bottom:-${i}px;opacity:0;}#${e} a{-webkit-box-align:center;align-items:center;background:${a};border-radius:${i}px;color:${l};cursor:pointer;display:-webkit-box;display:flex;font-size:${d}px;height:${i}px;-webkit-box-pack:center;justify-content:center;text-decoration:none;width:${i}px;}`,n=document.createElement("style");n.appendChild(document.createTextNode(t)),document.head.insertAdjacentElement("afterbegin",n)}();const p=function(){const n=document.createElement("div");n.id=e;const i=document.createElement("a");return i.addEventListener("click",e=>{e.preventDefault(),t.scrollTop=o}),i.appendChild(c),n.appendChild(i),document.body.appendChild(n),n}();let m;u(),(t===document.documentElement?window:t).addEventListener("scroll",()=>{t.scrollTop>=n?function(){if(!m)return;p.className="",m=!1}():u()});function u(){m||(p.className="hidden",m=!0)}} | ||
function addBackToTop(e){var t=e.id,o=void 0===t?"back-to-top":t,n=e.scrollContainer,c=void 0===n?document.documentElement:n,i=e.showWhenScrollTopIs,a=void 0===i?300:i,d=e.onClickScrollTo,r=void 0===d?0:d,l=e.innerElement,s=void 0===l?document.createTextNode("Up"):l,p=e.size,m=void 0===p?50:p,u=e.fontSize,f=void 0===u?14:u,x=e.cornerOffset,b=void 0===x?20:x,v=e.backgroundColor,k=void 0===v?"#000":v,h=e.textColor,y=void 0===h?"#fff":h,w=e.zIndex,g=void 0===w?1:w;!function(){var e="#".concat(o,"{bottom:").concat(b,"px;opacity:1;position:fixed;right:").concat(b,"px;-webkit-transition:bottom .2s,opacity .2s;transition:bottom .2s,opacity .2s;z-index:").concat(g,";}#").concat(o,".hidden{bottom:-").concat(m,"px;opacity:0;}#").concat(o," a{-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;background:").concat(k,";border-radius:").concat(m,"px;color:").concat(y,";cursor:pointer;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:").concat(f,"px;height:").concat(m,"px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;text-decoration:none;width:").concat(m,"px;}"),t=document.createElement("style");t.appendChild(document.createTextNode(e)),document.head.insertAdjacentElement("afterbegin",t)}();var E,C=function(){var e=document.createElement("div");e.id=o;var t=document.createElement("a");return t.addEventListener("click",function(e){e.preventDefault(),c.scrollTop=r}),t.appendChild(s),e.appendChild(t),document.body.appendChild(e),e}();T(),(c===document.documentElement?window:c).addEventListener("scroll",function(){c.scrollTop>=a?function(){if(!E)return;C.className="",E=!1}():T()});function T(){E||(C.className="hidden",E=!0)}} |
{ | ||
"name": "vanilla-back-to-top", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "Configurable zero dependency Back To Top button", | ||
@@ -25,2 +25,13 @@ "main": "dist/vanilla-back-to-top.min.js", | ||
}, | ||
"browserslist": [ | ||
"ie >=10", | ||
"edge >=15", | ||
"firefox >=28", | ||
"chrome >=21", | ||
"safari >=6.1", | ||
"opera >=15", | ||
"ios >=7.1", | ||
"android >=4.4", | ||
">= 0.5%" | ||
], | ||
"author": "Vladimir Feskov", | ||
@@ -27,0 +38,0 @@ "license": "MIT", |
# Vanilla Back To Top | ||
Configurable zero dependency Back To Top button. | ||
Configurable zero dependency Back To Top button that will work for [over 95% of all users](http://browserl.ist/?q=ie+%3E%3D10%2Cedge+%3E%3D15%2Cfirefox+%3E%3D28%2Cchrome+%3E%3D21%2Csafari+%3E%3D6.1%2Copera+%3E%3D15%2Cios+%3E%3D7.1%2Candroid+%3E%3D4.4%2C%3E%3D0.5%25) worldwide. | ||
@@ -13,12 +13,6 @@ Ideal for pre-rendered blogs with no frameworks, e.g., [Hexo](https://hexo.io/). | ||
``` | ||
<script src="https://unpkg.com/vanilla-back-to-top@2.0.1/dist/vanilla-back-to-top.min.js"></script> | ||
<script src="https://unpkg.com/vanilla-back-to-top@3.0.0/dist/vanilla-back-to-top.min.js"></script> | ||
<script>addBackToTop({})</script> | ||
``` | ||
If you want to target older browsers and IE 10 add this instead (~15% larger when gzipped): | ||
``` | ||
<script src="https://unpkg.com/vanilla-back-to-top@2.0.1/dist/vanilla-back-to-top.ie10.min.js"></script> | ||
<script>addBackToTop({})</script> | ||
``` | ||
Optionally customise CSS of the button using `#back-to-top` selector, e.g.: | ||
@@ -69,1 +63,17 @@ ``` | ||
- `scrollContainer` - if only part of your website gets scrolled, e.g., when your sidebar never scrolls with content, put the scrolled DOM element here | ||
## Supported browsers | ||
- IE >=10, | ||
- Edge >=15 | ||
- Firefox >=28 | ||
- Chrome >=21 | ||
- Safari >=6.1 | ||
- Opera >=15 | ||
- iOS Safari >=7.1 | ||
- Android Browser >=4.4 | ||
- All other browsers used by more than 0.5% of users | ||
This gives [95.12% global coverage](http://browserl.ist/?q=ie+%3E%3D10%2Cedge+%3E%3D15%2Cfirefox+%3E%3D28%2Cchrome+%3E%3D21%2Csafari+%3E%3D6.1%2Copera+%3E%3D15%2Cios+%3E%3D7.1%2Candroid+%3E%3D4.4%2C%3E%3D0.5%25). | ||
On Opera Mini and IE 10 the button doesn't appear or disappear as nicely as in other browsers, otherwise it's fully functional. |
78
5535
3