Skip to content

Instantly share code, notes, and snippets.

@ElfhirDev
Created June 29, 2016 09:58
Show Gist options
  • Save ElfhirDev/35366cb50e5ef4b3300a83b0ab9c0cd6 to your computer and use it in GitHub Desktop.
Save ElfhirDev/35366cb50e5ef4b3300a83b0ab9c0cd6 to your computer and use it in GitHub Desktop.
Add a fixed button for go to top on website without it.
// ==UserScript==
// @name go to top
// @namespace gototop
// @description Add a button to go to top
// @include *
// @version 1
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js
// ==/UserScript==
$(document).ready(function () {
$('body').append('<div id=\'gototop\'>&#8593;</div>');
$('#gototop').css({
'position': 'fixed',
'left': '96.5%',
'bottom': '5px',
'padding': '5px',
'width': '50px',
'z-index': '99999',
'font-size': '26px',
'text-align': 'center',
'vertical-align': 'middle',
'background': 'rgba(0,0,0,0.8)',
'color': '#efefef',
'border-radius': '10px',
'box-shadow': 'inset 0 0 10px 10px rgba(0,0,0,0.5)',
"cursor": "pointer"
});
$('#gototop').on('mousedown', function (e) {
switch(e.which) {
case 1:
document.body.scrollTop = document.documentElement.scrollTop = 0;
break;
case 3:
$('#gototop').remove();
break;
case 2:
default:
document.body.scrollTop = document.documentElement.scrollTop = 0;
break;
}
});
});
@ElfhirDev
Copy link
Author

ElfhirDev commented Jun 29, 2016

Right click will remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment