Difference between revisions of "Template:Team:CHINA CD UESTC/basicjs"

Line 1: Line 1:
function f1(){
+
$(document).ready(function() {
$(window).scroll(function() {
+
    var offset = 250, // At what pixels show Back to Top Button
if($(window).scrollTop() >= 100){
+
        scrollDuration = 300; // Duration of scrolling to top
$('.actGotop').fadeIn(300);  
+
    $(window).scroll(function() {
}else{  
+
        if ($(this).scrollTop() > offset) {
$('.actGotop').fadeOut(300);
+
            $('.top').fadeIn(500); // Time(in Milliseconds) of appearing of the Button when scrolling down.
}
+
        } else {
});
+
            $('.top').fadeOut(500); // Time(in Milliseconds) of disappearing of Button when scrolling up.
$('.actGotop').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});
+
        }
 +
    });
 +
 
 +
    // Smooth animation when scrolling
 +
    $('.top').click(function(event) {
 +
        event.preventDefault();
 +
        $('html, body').animate({
 +
            scrollTop: 0
 +
        }, scrollDuration);
 +
    })
 
});
 
});

Revision as of 00:18, 16 September 2015

$(document).ready(function() {

   var offset = 250, // At what pixels show Back to Top Button
       scrollDuration = 300; // Duration of scrolling to top
   $(window).scroll(function() {
       if ($(this).scrollTop() > offset) {
           $('.top').fadeIn(500); // Time(in Milliseconds) of appearing of the Button when scrolling down.
       } else {
           $('.top').fadeOut(500); // Time(in Milliseconds) of disappearing of Button when scrolling up.
       }
   });
   // Smooth animation when scrolling
   $('.top').click(function(event) {
       event.preventDefault();
       $('html, body').animate({
           scrollTop: 0
       }, scrollDuration);
   })

});