Team:NYMU-Taipei/menu.js

From 2014.igem.org

(Difference between revisions)
m
m
Line 13: Line 13:
             }, this), 100));   
             }, this), 100));   
             if($(this).hasClass('now')) return ;
             if($(this).hasClass('now')) return ;
-
             $(this).find('a > span').stop(true,true).animate({opacity: '0'}, 700);
+
             $(this).find('a > span').stop(true,true).animate({opacity: '0'}, 500);
        
        
         })
         })
Line 37: Line 37:
   $(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;
-
         $.get( toUrl , function(data) {
+
         loadPage(toUrl);
-
            $('#main-content').html($(data).find('#main-content').html());
+
       
-
        });
+
   });
   });
   $('#menu a').click(function(e){      //to get the ajax content and display in div 'main-content'
   $('#menu a').click(function(e){      //to get the ajax content and display in div 'main-content'
         e.preventDefault();
         e.preventDefault();
         var toUrl=$(this).attr('href');
         var toUrl=$(this).attr('href');
-
         var location='https://2014.igem.org'+toUrl;
+
         loadPage(toUrl);
-
 
+
-
        $.get( toUrl , function(data) {
+
-
            $('#main-content').html($(data).find('#main-content').html());
+
-
        });
+
          
          
-
         if(toUrl!=window.location.href){      //to change the browser URL to the given link location
+
         if(toUrl!=window.location.pathname){      //to change the browser URL to the given link location
               window.history.pushState({path:toUrl},'',toUrl);
               window.history.pushState({path:toUrl},'',toUrl);
         }
         }
   });
   });
});
});
 +
 +
var loadPage=function(toUrl){
 +
      $.get( toUrl , function(data) {
 +
            $('#main-content').html($(data).find('#main-content').html());
 +
            if(toUrl=='/Team:NYMU-Taipei/team/member'){
 +
                    teamMemFunc();
 +
    }
 +
      });
 +
};
 +
 +
var teamMemFunc=function(){
 +
      console.log('xd');
 +
}

Revision as of 14:37, 28 June 2014

$( 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).scroll(function (event){
        var y = $(this).scrollTop();
        if(y>240){
            $('#menu').css({
                marginTop:0,
            });
        }
        else{
            $('#menu').css({
               marginTop:240-y,  
            });
        }
 });
 $(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);
        }
 });

});

var loadPage=function(toUrl){

      $.get( toUrl , function(data) {
            $('#main-content').html($(data).find('#main-content').html());
            if(toUrl=='/Team:NYMU-Taipei/team/member'){
                   teamMemFunc();

}

      });

};

var teamMemFunc=function(){

      console.log('xd');

}