Created
June 29, 2016 09:58
-
-
Save ElfhirDev/35366cb50e5ef4b3300a83b0ab9c0cd6 to your computer and use it in GitHub Desktop.
Add a fixed button for go to top on website without it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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\'>↑</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; | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right click will remove it.