Team:NYMU-Taipei/menu.js
From 2014.igem.org
Line 28: | Line 28: | ||
.on('mouseenter',function(){ | .on('mouseenter',function(){ | ||
$(this).find('span').css({'display':'block',opacity: '1'}); | $(this).find('span').css({'display':'block',opacity: '1'}); | ||
+ | $(this).find('ul').stop(true,true).show("slide", { direction: "right" }, 300); | ||
}) | }) | ||
.on('mouseleave',function(){ | .on('mouseleave',function(){ | ||
$(this).find('span').css({'display':'none',opacity: '1'}); | $(this).find('span').css({'display':'none',opacity: '1'}); | ||
+ | $(this).find('ul').stop(true,true).hide("slide", { direction: "left" }, 300); | ||
}); | }); | ||
$(window).scroll(function (event){ | $(window).scroll(function (event){ |
Revision as of 10:52, 27 September 2014
$(window).on('beforeunload', function() {
$(window).scrollTop(0);
}); $( 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'}, 300); }) .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'}); }); $('#menu > ul > li > ul > li') .on('mouseenter',function(){ $(this).find('span').css({'display':'block',opacity: '1'}); $(this).find('ul').stop(true,true).show("slide", { direction: "right" }, 300); }) .on('mouseleave',function(){ $(this).find('span').css({'display':'none',opacity: '1'}); $(this).find('ul').stop(true,true).hide("slide", { direction: "left" }, 300); }); $(window).scroll(function (event){ var y = $(window).scrollTop(); /* if(window.location.pathname=='/Team:NYMU-Taipei'){ //$('.header').css({'background-position':'20% '+(40+y)+'px' }); } else{ } $('.outlink').css({marginTop: 200-y,}); */ if(y>290){ $('#menu').css({'position':'fixed','margin-top':0}); } else{ $('#menu').css({'position':'absolute','margin-top':'290px'}); } });
$(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); //tooth// var move=0; $('#toothy').on('mousedown',function(){ move=1; }) .on('mouseup',function(){ move=0; }); $('#toothy').children().on('mousedown',function(e){e.stopPropagation();}); $(window).on('mousemove',function(e){ if(move==0) return ; var x=e.clientX; var y=e.clientY; var dx=$(window).scr $('#toothy').css({left:x-50,top:y-50}); }); questionGameFunction(); //// var clickcloud=0; $('#cloud>div').click(function(){ clickcloud=1; $('#cloud').stop(true,true).animate({'top':'-200px'},700); $('#cloud>div').stop(true,true).animate({'top':'115px'},700); $('#clickthecloud').stop(true,true).animate({opacity:0},400); }) .on('mouseleave',function(){ if(clickcloud==0) return ; $('#cloud').stop(true,true).animate({'top':'-85px'},700); $('#cloud>div').stop(true,true).animate({'top':'0px'},700); $('#clickthecloud').stop(true,true).animate({opacity:1},1400); });
});
var loadPage=function(toUrl){
$.get( toUrl , function(data) { $('html,body').animate({scrollTop: 0},700); $('#main-content').html($(data).find('#main-content').html()); PageFunction(toUrl); });
};
var PageFunction=function(toUrl){
$('.header').css({'background-position': '20% 40px','background-attachment': 'scroll'}); $('#main-content').css({'background':'rgba(255,255,255,0.85)'}); $('#menu > ul > li').each(function(){ var des=$(this).find('a').attr('href').split('/'); var res=toUrl.split('/'); if(des[2]==res[2]){ $(this).addClass('now'); $(this).find('a > span').css({opacity: '1'}); } else{ $(this).removeClass('now'); $(this).find('a > span').css({opacity: '0'}); } });
$('.cont-panel > div').click(function(){ var toAnchor=$(this).attr('href'); $('html, body').animate({ scrollTop: $(toAnchor).offset().top }, 0); }); var splitUrl=toUrl.split('/');
if(toUrl=='/Team:NYMU-Taipei/team/member'){ teamMemFunc(); } else if(toUrl=='/Team:NYMU-Taipei/team/gallery'){ teamGalFunc(); } else if(toUrl=='/Team:NYMU-Taipei'){
// $('.outlink').css({'margin-top':200}); $('#main-content').css({'background':'rgba(255,255,255,0)'}); HomeFunc(); } else if(toUrl=='/Team:NYMU-Taipei/notebook/labnotes'){ NbNotesFunc(); } else if(splitUrl[1]=='Team:NYMU-Taipei'&&splitUrl[2]=='modeling'){ MdlMathFunc(); }
};
var contentAjax=function(){
$('#main-content a').click(function(e){ 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 teamMemFunc=function(){
console.log('xd1'); $('.mem_pullbar').hover(function(){ var pic2=$(this).parent().find('.mem_pic2'); pic2.stop(true,true).animate({ bottom: 0 , opacity : 1},500); },function(){ var pic2=$(this).parent().find('.mem_pic2'); pic2.stop(true,true).animate({ bottom: -260 , opacity : 0.5},500); });
};
var teamGalFunc=function(){
var thumbs=$('.g-thumb').children();
var n=thumbs.length; var mainFrame=$('.main-img'); var nextbt=$('.g-left'); var prevbt=$('.g-right'); var nImages; var frameWidth=mainFrame.width(); var currId,prevId,nextId; var initFunction=function(){ currId=0; for(var i=0;i<n;i++){
var newDiv=$("");newDiv.css({'background':"url('"+thumbs.eq(i).attr('src')+"') 50% 50% no-repeat",'left':-frameWidth}); mainFrame.append(newDiv); } nImages=mainFrame.children().not(nextbt).not(prevbt); nImages.eq(0).css({'left':0}); }; var playNextFunction=function(duration){ nextId=(currId+1)%n; nImages.eq(nextId).css({'left':frameWidth}); nImages.eq(currId).stop(true,true).animate({'left':-frameWidth},duration); nImages.eq(nextId).stop(true,true).animate({'left':0},duration); currId=nextId; }; var playPrevFunction=function(duration){ prevId=(currId-1+n)%n; nImages.eq(prevId).css({'left':-frameWidth}); nImages.eq(currId).stop(true,true).animate({'left':frameWidth},duration); nImages.eq(prevId).stop(true,true).animate({'left':0},duration); currId=prevId; };
initFunction();
// setInterval(playNextFunction(700),5000);
nextbt.click(function(){ playNextFunction(700); }); prevbt.click(function(){ playPrevFunction(700); });
thumbs.click(function(){
var d=thumbs.index($(this)); var start=currId; if(d>start){ var p=(d-start+n)%n;
var duration=700;
for(var i=0;i<p;i++) playNextFunction(duration); } else{ var p=(start-d+n)%n;
var duration=700;for(var i=0;i
290){ $('#tabframe').css({'position':'fixed','top':'147px'}); } else{ $('#tabframe').css({'position':'absolute','top':'100px'}); } if($('#tabframe').offset().top-70>$('#labnote').height()){ $('#tabframe').css({'position':'absolute','top':$('#labnote').height()-270}); } }); $('.note-tab').click(function(){ $(window).scrollTop(287); var show='#'+$(this).attr('id')+'-cont'; $('.notenow').css({'display':'none'}); $('.notenow').removeClass('notenow'); $(show).css({'display':'block'}); $(show).addClass('notenow'); }); }; var MdlMathFunc=function(){ MathJax.Hub.Typeset(); contentAjax(); } var questionGameFunction=function(){ var data; var dialog=$('#dialog'); var qnaNextBt=$('#qnaNextBt'); var qnaPrevBt=$('#qnaPrevBt'); var closeBt=$('#qnaClose'); var openBt=$('#convopen'); var status=0; var qId=-3; $.getJSON('/Team:NYMU-Taipei/QnAgame.json?action=raw',function(Jdata){ data=Jdata; }); var showResponce=function(res){ var s; if(res){ //yes s='<p>yay :)
';} else{ //no
s='oh, not right.
';} dialog.html(s); }
var showQuestion=function(){ var s;
s=""+data[qId]["Q"]+"
";
for(var i=0;i<data[qId]["S"].length;i++){
s+="<input type='radio' name='op' value='"+i+"'>";
s+=data[qId]["S"][i];
s+="
";
}
dialog.html(s);
}
var startConv=function(){ if(qId==-3) qnaPrevBt.css({'display':'none'}); else qnaPrevBt.css({'display':'block'});var s=["
Hi, my name is toothy, Nice to meet you :). Welcome to the wiki page of NYMU-Taipei in iGEM 2014.Our project this year is 'TACKLE TOOTH'.
","By visiting our wiki, you can get more information.However, I have some questions and need your help. You can find all the answers in our wiki.
","You can drag me to anyplace in the website. If you think I am a little annoying, just put me to the corner(hope you won't do so). Anyway, just explore and have fun!!
"];dialog.html(s[qId+3]); status=0;
}
var endConv=function(){var s="
Hope you have a good time visiting our wiki. Enjoy it!
";dialog.html(s); qnaNextBt.css({'display':'none'}); }
qnaNextBt.click(function(){
if(qId<0){ //start mode qId++; if(qId<0){ startConv(); return ; } else{ showQuestion(qId); } }
if(status){ //question mode var p=$('input[name="op"]:checked').val(); showResponce( p==data[qId]["A"] ? 1:0 );
qId++;
} else{ //response mode
if(qId>=data.length){ endConv(); }
else{
showQuestion(qId); } }
status=1-status;
qnaPrevBt.css({'display':'block'});
}); qnaPrevBt.click(function(){
qId--; if(qId<0){ startConv(); return ; } status=1; showQuestion(qId); qnaNextBt.css({'display':'block'}); }); closeBt.click(function(){ dialog.css({'display':'none'}); qnaNextBt.css({'display':'none'}); qnaPrevBt.css({'display':'none'}); closeBt.css({'display':'none'}); openBt.css({'display':'block'}); }); openBt.click(function(){ dialog.css({'display':'block'}); qnaNextBt.css({'display':'block'}); qnaPrevBt.css({'display':'block'}); closeBt.css({'display':'block'}); openBt.css({'display':'none'}); });
startConv();
};