Created
October 15, 2011 13:51
-
-
Save maxpert/1289593 to your computer and use it in GitHub Desktop.
Minimal jQuery Autoscroll to top
This file contains 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
(function(jq) { | |
jq.autoScroll = function(ops) { | |
ops = ops || {}; | |
ops.styleClass = ops.styleClass || 'scroll-to-top-button'; | |
var t = jq('<div class="'+ops.styleClass+'"></div>'), | |
d = jq(ops.target || document); | |
jq(ops.container || 'body').append(t); | |
t.css({ | |
opacity: 0, | |
position: 'absolute', | |
top: 0, | |
right: 0 | |
}).click(function() { | |
jq('html,body').animate({ | |
scrollTop: 0 | |
}, ops.scrollDuration || 1000); | |
}); | |
d.scroll(function() { | |
var sv = d.scrollTop(); | |
if (sv < 10) { | |
t.clearQueue().fadeOut(ops.hideDuration || 200); | |
return; | |
} | |
t.css('display', '').clearQueue().animate({ | |
top: sv, | |
opacity: 0.8 | |
}, ops.showDuration || 500); | |
}); | |
}; | |
})(jQuery); |
This file contains 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
$(document).ready(function(){ | |
$.autoScroll({ | |
scrollDuration: 2000, | |
showDuration: 600, | |
hideDuration: 300 | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment