Team:NYMU-Taipei/menu.js

From 2014.igem.org

(Difference between revisions)
m
m
Line 1: Line 1:
 +
$(window).scroll(function (event){
 +
        var y = $(this).scrollTop();
 +
        if(window.location.pathname=='/Team:NYMU-Taipei'){
 +
            $('#menu').css({
 +
                marginTop:14-y, 
 +
            });
 +
            $('.header').css({'background-position': '192px 40px','background-attachment': 'fixed'});
 +
            return ;
 +
        }
 +
        else if(y>290){
 +
            $('#menu').css({
 +
                marginTop:0,
 +
            });
 +
            $('.header').css({'background-position': '0px 40px','background-attachment': 'scroll'});
 +
        }
 +
        else{
 +
            $('#menu').css({
 +
                marginTop:290-y, 
 +
            });
 +
        }
 +
  });
$( document ).ready(function() {
$( document ).ready(function() {
   $('#menu > ul > li')
   $('#menu > ul > li')
Line 22: Line 43:
             $('#menu > ul > li').not(this).find('a > span').css({opacity: '0'});
             $('#menu > ul > li').not(this).find('a > span').css({opacity: '0'});
         });     
         });     
-
   $(window).scroll(function (event){
+
    
-
        var y = $(this).scrollTop();
+
-
        if(window.location.pathname=='/Team:NYMU-Taipei'){
+
-
            $('#menu').css({
+
-
                marginTop:14-y, 
+
-
            });
+
-
            $('.header').css({'background-position': '192px 40px','background-attachment': 'fixed'});
+
-
            return ;
+
-
        }
+
-
        else if(y>290){
+
-
            $('#menu').css({
+
-
                marginTop:0,
+
-
            });
+
-
          //  $('.header').css({'background-position': '0px 40px','background-attachment': 'scroll'});
+
-
        }
+
-
        else{
+
-
            $('#menu').css({
+
-
                marginTop:290-y, 
+
-
            });
+
-
        }
+
-
  });
+
   $(window).bind('popstate', function() {    //override back button to get the ajax content without page reload
   $(window).bind('popstate', function() {    //override back button to get the ajax content without page reload
         var toUrl=location.pathname;
         var toUrl=location.pathname;

Revision as of 02:33, 12 July 2014

$(window).scroll(function (event){

        var y = $(this).scrollTop();
        if(window.location.pathname=='/Team:NYMU-Taipei'){
            $('#menu').css({
               marginTop:14-y,  
            });
            $('.header').css({'background-position': '192px 40px','background-attachment': 'fixed'});
            return ;
        }
        else if(y>290){
            $('#menu').css({
                marginTop:0,
            });
            $('.header').css({'background-position': '0px 40px','background-attachment': 'scroll'});
        }
        else{
            $('#menu').css({
               marginTop:290-y,  
            });
        }
 });

$( document ).ready(function() {

 $('#menu > ul > li')
       .on('mouseenter', function(){
           clearTimeout($.data(this,'timer'));
           $(this).find('ul').stop(true,true).slideDown(200);  
           if($(this).hasClass('now')) return ;
           $(this).find('a > span').stop(true,true).animate({opacity: '1'}, 300);
      
       })
       .on('mouseleave', function(){
           $.data(this,'timer', setTimeout($.proxy(function() {
           $(this).find('ul').stop(true,true).slideUp(200);
           }, this), 100));  
           if($(this).hasClass('now')) return ;
           $(this).find('a > span').stop(true,true).animate({opacity: '0'}, 500);
     
       })
       .click( function(){
           $('#menu > ul > li').removeClass('now');
           $(this).addClass('now');
           $(this).find('a > span').stop(true,true).animate({opacity: '1'}, 300);
           $('#menu > ul > li').not(this).find('a > span').css({opacity: '0'});
       });    
 
 $(window).bind('popstate', function() {    //override back button to get the ajax content without page reload
        var toUrl=location.pathname;
        loadPage(toUrl);
 });
 $('#menu a').click(function(e){      //to get the ajax content and display in div 'main-content'
        e.preventDefault();
        var toUrl=$(this).attr('href');
        loadPage(toUrl);
        
        if(toUrl!=window.location.pathname){      //to change the browser URL to the given link location
             window.history.pushState({path:toUrl},,toUrl);
        }
 });
 PageFunction(window.location.pathname);

});

var loadPage=function(toUrl){

      if($(window).scrollTop()>0) $(window).scrollTop(0);
      $.get( toUrl , function(data) {
            $('#main-content').html($(data).find('#main-content').html());
            PageFunction(toUrl);
      });

};

var PageFunction=function(toUrl){

      var y=$(window).scrollTop();
      $('#menu').css({'margin-top':-y+290});


      $('#menu > ul > li').each(function(){
              if($(this).find('a').attr('href')==toUrl){
                   $(this).addClass('now');
                   $(this).find('a > span').css({opacity: '1'});
              }
              else{
                   $(this).removeClass('now');
                   $(this).find('a > span').css({opacity: '0'});
              }
        });
      if(toUrl=='/Team:NYMU-Taipei/team/member'){
            teamMemFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei/team/lab'){
            teamLabFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei'){
            $('#menu').css({'margin-top':-y+14});
            HomeFunc();
      }
      else if(toUrl=='/Team:NYMU-Taipei/notebook/journal'){
            NbJrnlFunc();
      }

};

var teamMemFunc=function(){

      console.log('xd1');

};

var teamLabFunc=function(){

      console.log('xd2');

};

var HomeFunc=function(){ };

var NbJrnlFunc=function(){ };