Difference between revisions of "Template:NCKU Tainan/js/main js"

 
Line 64: Line 64:
 
       });
 
       });
 
     });
 
     });
 
function show(id1,id2){
 
    $(id1).toggleClass('active');
 
    $(id2).toggleClass('active');
 
  }
 

Latest revision as of 02:40, 30 October 2017

function moveTimeout(t, i) {

     setTimeout(function() {
       window.scrollTo(0, i);
     }, t * 20);
   }
   function scrollto(id){
     time_delay = 0;
     var temp =document.documentElement.scrollTop;
     var destination = $(id).offset().top-80;
     if(temp < destination){
       while(temp+30 <= (destination+50)){
         moveTimeout(time_delay,temp);
         temp+=10;
         time_delay+=0.05;
       }
       moveTimeout(time_delay,temp);
   }
     else{
       while(temp-30 >= destination){
         moveTimeout(time_delay,temp);
         temp-=10;
         time_delay+=0.05;
       }
       moveTimeout(time_delay,temp);
     }
 }


         function moveTimeout(t, i) {
           setTimeout(function() {
             window.scrollTo(0, i);
           }, t * 20);
         }
         function scrollbot(id){
           time_delay = 0;
           var temp =document.documentElement.scrollTop;
           var destination = $(id).offset().top;
           while(temp+20 <= destination){
             moveTimeout(time_delay,temp);
             temp+=20;
             time_delay+=1;
           }
           moveTimeout(time_delay,temp);
       }
   $(document).ready(function() {
     // Transition effect for navbar
     $(window).scroll(function() {
       // checks if window is scrolled more than 300px, adds/removes solid class
       if ($(this).scrollTop() >= 680) {
         // $('.navbar').addClass('solid');
         var position = $("#sidemenu").position();
         if(position == undefined){}
         else{
           $('#sidemenu').css({"position": "fixed", "top": "35px","left": position.left});
         }
       } else {
         // $('.navbar').removeClass('solid');
         $('#sidemenu').removeAttr('style');
       }
     });
   });