Team:Uppsala/JavaScript
From 2014.igem.org
(Difference between revisions)
Line 1: | Line 1: | ||
- | + | jQuery(document).ready(function() { | |
- | + | var stats = ('.back-to-top'), timer; | |
- | + | var offset = 220; | |
- | + | var duration = 1000; | |
- | + | jQuery(window).scroll(function() { | |
- | + | if (jQuery(this).scrollTop() > offset) { | |
- | + | jQuery(stats).fadeIn(duration); | |
- | + | clearTimeout(timer); | |
- | + | ||
- | stats.fadeIn(); | + | |
- | clearTimeout(timer); | + | |
timer = setTimeout(function() { | timer = setTimeout(function() { | ||
- | + | jQuery(stats).fadeOut(duration)}, 3000); | |
- | + | ||
- | + | ||
} | } | ||
- | }); | + | |
- | + | }); | |
- | + | ||
- | + | jQuery(stats).click(function(event) { | |
- | + | event.preventDefault(); | |
- | + | jQuery('html, body').animate({scrollTop: 0}, duration); | |
- | + | return false; | |
- | + | }); | |
- | + | ||
}); | }); | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- |
Revision as of 13:15, 16 July 2014
jQuery(document).ready(function() {
var stats = ('.back-to-top'), timer; var offset = 220; var duration = 1000; jQuery(window).scroll(function() { if (jQuery(this).scrollTop() > offset) { jQuery(stats).fadeIn(duration); clearTimeout(timer); timer = setTimeout(function() { jQuery(stats).fadeOut(duration)}, 3000); } }); jQuery(stats).click(function(event) { event.preventDefault(); jQuery('html, body').animate({scrollTop: 0}, duration); return false; });
});