Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //On Page Load
- initReturnToTop();
- //Functions below
- function initReturnToTop() {
- //setup our html
- var returnDiv = '\
- <div id="ReturnToTop" style="position:fixed; cursor:pointer; color:#0096ff; font-size:0.7em; background-color:#171717; -moz-border-bottom-left-radius: 13px; border-bottom-left-radius: 13px; -moz-border-bottom-right-radius: 13px; border-bottom-right-radius: 13px; border:2px solid #2b2b2b; padding:2px; padding-left:10px; padding-right:10px; z-index:1000; top:-10px; right:0px;">RETURN TO TOP</div>\
- ';
- $('body').prepend(returnDiv);
- //hook into scroll and resize events
- $(window).scroll(function () {
- processReturnToTop();
- });
- $( window ).resize(function() {
- processReturnToTop();
- });
- //setup a click handler
- $('#ReturnToTop').click(function(){
- $("html, body").animate({ scrollTop: 0 }, 300);
- });
- //run the sub-routine manually once at page load
- processReturnToTop();
- }
- function processReturnToTop() {
- var threshold = 300; //The higher the number, the further down the page the widget rolls in
- var curOffset = $(document).scrollTop();
- if (curOffset > threshold) {
- $('#ReturnToTop').animate({
- 'top':parseInt($('#pvpnet-bar').height()) + 'px'
- },500);
- } else {
- $('#ReturnToTop').stop(true).animate({
- 'top':0
- },500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment