Team:SYSU-China/js/project.js
From 2014.igem.org
(Created page with "$(function() { var subList = []; $(".sidebar li").each(function() { $(this).hoverDelay({ hoverDuring: 200, outDuring: 400, hoverEvent: function() { if...") |
|||
(46 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
$(function() { | $(function() { | ||
- | var | + | var navicon = ["Project", "Judging", "HumanPractice", "Team"]; |
+ | var urlHash = ["Project/Background", "Judging/Safetyform", "HumanPractice/iGEMCC", "Team/Ourteam"]; | ||
+ | var colors = ["#b5c90f", "#ed8f6b", "#7aa59e", "#ed9d60"]; | ||
- | $(". | + | function navigationSet() { |
+ | var icon1 = ["https://static.igem.org/mediawiki/2014/f/fb/Bg31.png", | ||
+ | "https://static.igem.org/mediawiki/2014/7/79/Bg34.png", | ||
+ | "https://static.igem.org/mediawiki/2014/e/e2/Bg33.png", | ||
+ | "https://static.igem.org/mediawiki/2014/0/09/Bg35.png"]; | ||
+ | var icon2 = ["https://static.igem.org/mediawiki/2014/5/5b/Sysuchina_bg31.png", | ||
+ | "https://static.igem.org/mediawiki/2014/5/5e/Sysuchina_bg34.png", | ||
+ | "https://static.igem.org/mediawiki/2014/7/74/Sysuchina_bg33.png", | ||
+ | "https://static.igem.org/mediawiki/2014/2/27/Sysuchina_bg35.png"]; | ||
+ | $(".dl-menu").each(function(i) { | ||
+ | $(this).css("background-color", colors[i]); | ||
+ | $(this).children().each(function() { | ||
+ | $($(this).children()[1]).css("background-color", colors[i]); | ||
+ | }); | ||
+ | }); | ||
+ | $(".navibar img").each(function(index) { | ||
+ | $(this).hover(function() { | ||
+ | var newSrc = $(this).attr("src").replace(icon2[index], icon1[index]); | ||
+ | $(this).attr("src", newSrc); | ||
+ | //$(this).css({"width" : "45px", "height" : "45px"}); | ||
+ | }, function() { | ||
+ | var newSrc = $(this).attr("src").replace(icon1[index], icon2[index]); | ||
+ | $(this).attr("src", newSrc); | ||
+ | //$(this).css({"width" : "40px", "height" : "40px"}); | ||
+ | }).trigger("mousehover"); | ||
- | + | $(this).click(function() { | |
- | + | gotoTop(1); | |
- | + | var hrefhash = urlHash[index]; | |
- | + | $.locationHash(hrefhash); | |
- | + | }); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
}); | }); | ||
- | } | + | } |
- | + | function fixscroll() { | |
- | $( | + | //获取要定位元素距离浏览器顶部的距离 |
- | + | var navH = $($(".navibar")[0]).position().top; | |
- | + | var nav2H = $($(".navigation2")[0]).position().top; | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
+ | //滚动条事件 | ||
+ | $(window).scroll(function(){ | ||
+ | //获取滚动条的滑动距离 | ||
+ | var scroH = $(document).scrollTop(); | ||
+ | //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定 | ||
+ | if(scroH >= navH){ | ||
+ | $(".navibar").css({"position":"fixed","top":"0"}); | ||
+ | } else if(scroH < navH){ | ||
+ | $(".navibar").css({"position":"absolute", "top" : "204px"}); | ||
} | } | ||
- | |||
- | |||
- | + | if(scroH >= nav2H){ | |
- | + | $(".navigation2").css({"position":"fixed","top": "60px"}); | |
- | + | } else if(scroH < nav2H){ | |
- | + | $(".navigation2").css({"position":"absolute", "top" : "264px"}); | |
- | + | } | |
- | + | }); | |
- | + | } | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | } | + | |
Line 101: | Line 74: | ||
} | } | ||
+ | function requestFile() { | ||
+ | var lochash = $.locationHash(); | ||
+ | $.get( | ||
+ | "https://2014.igem.org/Team:SYSU-China/file/" + lochash + ".html?action=raw", | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
function(data){ | function(data){ | ||
- | + | var realdata = data.substring(data.indexOf("<!--SYSUCHINA-->"),data.indexOf("<!--SYSUCHINA!-->")); | |
- | + | setTimeout(function() { | |
- | + | $($(".content")[0]).html(realdata); | |
- | } | + | }, 100); |
- | + | } | |
); | ); | ||
+ | gotoTop(1); | ||
} | } | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
function gotoTop(speed) { | function gotoTop(speed) { | ||
$('body,html').animate({scrollTop:0},speed); | $('body,html').animate({scrollTop:0},speed); | ||
Line 207: | Line 94: | ||
function top() { | function top() { | ||
- | $("# | + | $("#gotop").click(function() { |
- | gotoTop(); | + | gotoTop(100); |
+ | |||
}); | }); | ||
} | } | ||
Line 214: | Line 102: | ||
function jQueryHash() { // hash change listener | function jQueryHash() { // hash change listener | ||
$(window).hashchange(function() { | $(window).hashchange(function() { | ||
- | var | + | /*change page position*/ |
- | var | + | /*change file*/ |
- | + | requestFile(); | |
- | + | $('.single-item div').each(function() { | |
- | + | $(this).hide(); | |
+ | }); | ||
+ | /*change top image*/ | ||
+ | var hash = $.locationHash(); | ||
+ | var hashlist = hash = hash.split('/'); | ||
+ | var hashnum = hashlist.length; | ||
+ | var index = navicon.indexOf(hashlist[0]); | ||
+ | if (hash != "" && hashnum == 0) { | ||
+ | hashlist.push(hash); | ||
+ | hashnum = 1; | ||
+ | } | ||
+ | if (hashnum == 0) { | ||
+ | $($('.single-item div')[0]).show(); | ||
+ | } else { | ||
+ | if (index != -1) | ||
+ | $($('.single-item div')[index]).show(); | ||
+ | } | ||
+ | $(".dl-menu").each(function() { | ||
+ | $(this).hide(); | ||
+ | }); | ||
+ | $($(".dl-menu")[index]).show(); | ||
+ | $($("#sidenav button")[0]).css("background-color", colors[index]); | ||
}); | }); | ||
} | } | ||
Line 263: | Line 172: | ||
} | } | ||
- | function | + | function linkHome() { |
- | + | $(".single-item img").each(function() { | |
- | + | $(this).click(function() { | |
- | + | location.href = "https://2014.igem.org/Team:SYSU-China"; | |
- | + | }); | |
- | + | }); | |
- | + | } | |
- | + | function imgbox() { | |
- | + | $(".fancybox").fancybox(); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
} | } | ||
- | function | + | function flexnavi() { |
- | + | $(".flexnav").flexNav(); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
} | } | ||
- | function | + | var Navhover = [false, false, false, false, false]; |
+ | function navigation() { | ||
+ | $(".navibar img").each(function(index) { | ||
+ | $(this).hover( function() { | ||
+ | $($(".firstNav")[index]).show(); | ||
- | + | }, function() { | |
- | function | + | setTimeout(function(){ |
- | + | if (!Navhover[index]) { | |
+ | //$($(".firstNav")[index]).trigger("mouseleave"); | ||
+ | $($(".firstNav")[index]).hide(); | ||
+ | Navhover[index] = false; | ||
+ | } | ||
+ | }, 50); | ||
+ | }); | ||
+ | }); | ||
+ | |||
+ | $(".firstNav").each(function(index) { | ||
+ | $(this).hover(function() { | ||
+ | Navhover[index] = true; | ||
+ | }, function() { | ||
+ | Navhover[index] = false; | ||
+ | $($(".firstNav")[index]).hide(); | ||
+ | }).trigger("mousehover"); | ||
+ | }); | ||
+ | |||
+ | $(".firstNav").each(function() { | ||
+ | $(this).hide(); | ||
+ | }); | ||
+ | |||
+ | $(window).resize(function() { | ||
+ | //document.location.reload(); | ||
+ | }); | ||
+ | } | ||
+ | /* | ||
+ | function modal() { | ||
+ | $('#myModal').reveal({ | ||
+ | animation: 'fadeAndPop', //fade, fadeAndPop, none | ||
+ | animationspeed: 300, //how fast animtions are | ||
+ | closeonbackgroundclick: true, //if you click background will modal close? | ||
+ | dismissmodalclass: 'close-reveal-modal', //the class of a button or element that will close an open modal | ||
+ | }); | ||
} | } | ||
+ | */ | ||
+ | function sidenav() { | ||
+ | $( '#dl-menu' ).dlmenu(); | ||
+ | $($("#dl-menu button")[0]).trigger("click"); | ||
+ | } | ||
+ | |||
+ | |||
+ | function ini() { | ||
+ | //alert("sd"); | ||
+ | $(".dl-menu").each(function() { | ||
+ | $(this).hide(); | ||
+ | }); | ||
+ | $($(".dl-menu")[0]).show(); | ||
- | + | $("#tipImg").hide(); | |
- | + | ||
- | + | ||
- | + | $($(".dl-menu")[0]).show(); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
+ | var currentHash = $.locationHash(); | ||
- | + | //getPage(); | |
+ | //routeTree(); | ||
+ | navigationSet(); | ||
+ | |||
+ | jQueryHash(); | ||
+ | flexnavi(); | ||
+ | //Tips(); | ||
+ | setTimeout(fixscroll, 10); | ||
+ | setTimeout(Tips, 50); | ||
+ | linkHome(); | ||
+ | //imgbox(); | ||
+ | navigation(); | ||
+ | //modal(); | ||
+ | sidenav(); | ||
+ | top(); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | ini(); | ||
}); | }); |
Latest revision as of 01:43, 18 October 2014
$(function() { var navicon = ["Project", "Judging", "HumanPractice", "Team"]; var urlHash = ["Project/Background", "Judging/Safetyform", "HumanPractice/iGEMCC", "Team/Ourteam"]; var colors = ["#b5c90f", "#ed8f6b", "#7aa59e", "#ed9d60"];
function navigationSet() { var icon1 = ["", "", "", ""]; var icon2 = ["", "", "", ""]; $(".dl-menu").each(function(i) { $(this).css("background-color", colors[i]); $(this).children().each(function() { $($(this).children()[1]).css("background-color", colors[i]); }); }); $(".navibar img").each(function(index) { $(this).hover(function() { var newSrc = $(this).attr("src").replace(icon2[index], icon1[index]); $(this).attr("src", newSrc); //$(this).css({"width" : "45px", "height" : "45px"}); }, function() { var newSrc = $(this).attr("src").replace(icon1[index], icon2[index]); $(this).attr("src", newSrc); //$(this).css({"width" : "40px", "height" : "40px"}); }).trigger("mousehover");
$(this).click(function() { gotoTop(1); var hrefhash = urlHash[index]; $.locationHash(hrefhash); }); }); }
function fixscroll() { //获取要定位元素距离浏览器顶部的距离 var navH = $($(".navibar")[0]).position().top; var nav2H = $($(".navigation2")[0]).position().top;
//滚动条事件 $(window).scroll(function(){ //获取滚动条的滑动距离 var scroH = $(document).scrollTop(); //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定 if(scroH >= navH){ $(".navibar").css({"position":"fixed","top":"0"}); } else if(scroH < navH){ $(".navibar").css({"position":"absolute", "top" : "204px"}); }
if(scroH >= nav2H){ $(".navigation2").css({"position":"fixed","top": "60px"}); } else if(scroH < nav2H){ $(".navigation2").css({"position":"absolute", "top" : "264px"}); } }); }
function stopBubble(e) {
// 如果提供了事件对象,则这是一个非IE浏览器
if ( e && e.stopPropagation ) { // 因此它支持W3C的stopPropagation()方法 e.stopPropagation(); } else { // 否则,我们需要使用IE的方式来取消事件冒泡 window.event.cancelBubble = true;
} }
function requestFile() { var lochash = $.locationHash(); $.get( "https://2014.igem.org/Team:SYSU-China/file/" + lochash + ".html?action=raw",
function(data){ var realdata = data.substring(data.indexOf(""),data.indexOf(""));
setTimeout(function() {
$($(".content")[0]).html(realdata);
}, 100);
} );
gotoTop(1);
}
function gotoTop(speed) { $('body,html').animate({scrollTop:0},speed); }
function top() { $("#gotop").click(function() { gotoTop(100);
}); }
function jQueryHash() { // hash change listener $(window).hashchange(function() { /*change page position*/ /*change file*/ requestFile(); $('.single-item div').each(function() { $(this).hide(); }); /*change top image*/ var hash = $.locationHash(); var hashlist = hash = hash.split('/'); var hashnum = hashlist.length; var index = navicon.indexOf(hashlist[0]); if (hash != "" && hashnum == 0) { hashlist.push(hash); hashnum = 1; } if (hashnum == 0) { $($('.single-item div')[0]).show(); } else { if (index != -1) $($('.single-item div')[index]).show(); } $(".dl-menu").each(function() { $(this).hide(); }); $($(".dl-menu")[index]).show(); $($("#sidenav button")[0]).css("background-color", colors[index]); }); }
var showTip = false;
function Tips() { $("#tip em").each(function(i, v) { $(this).hoverDelay({ hoverDuring: 200, outDuring: 200, hoverEvent: function() { var tooltipPosTop = $(this).position().top- $("#tipImg").outerHeight(); //alert(tooltipPosTop); var tooltipPosLeft = $(this).position().left; var tooltipPosLeft = tooltipPosLeft - (($("#tipImg").outerWidth()/2) - $(this).outerWidth()/2);
$("#tipImg").css({ 'left': tooltipPosLeft + "px", 'top': tooltipPosTop+"px" }).animate({'opacity':'1', 'marginTop':'0'}, 500); $("#tipImg").show(); }, outEvent: function() { showTip = true;
setTimeout(function() { if (showTip) { $("#tipImg").fadeOut(100); showTip = false;// do nothing } }, 200); } }); });
$("#tipImg").hoverDelay({ hoverDuring: 200, outDuring: 200, hoverEvent: function() { showTip = false; }, outEvent: function() { $("#tipImg").fadeOut(100); } }); }
function linkHome() { $(".single-item img").each(function() { $(this).click(function() { location.href = "https://2014.igem.org/Team:SYSU-China"; }); }); } function imgbox() { $(".fancybox").fancybox(); }
function flexnavi() { $(".flexnav").flexNav(); }
var Navhover = [false, false, false, false, false]; function navigation() { $(".navibar img").each(function(index) { $(this).hover( function() { $($(".firstNav")[index]).show();
}, function() {
setTimeout(function(){ if (!Navhover[index]) { //$($(".firstNav")[index]).trigger("mouseleave"); $($(".firstNav")[index]).hide(); Navhover[index] = false; } }, 50); });
});
$(".firstNav").each(function(index) { $(this).hover(function() { Navhover[index] = true; }, function() { Navhover[index] = false; $($(".firstNav")[index]).hide(); }).trigger("mousehover"); });
$(".firstNav").each(function() {
$(this).hide(); });
$(window).resize(function() {
//document.location.reload();
});
}
/* function modal() { $('#myModal').reveal({
animation: 'fadeAndPop', //fade, fadeAndPop, none animationspeed: 300, //how fast animtions are closeonbackgroundclick: true, //if you click background will modal close? dismissmodalclass: 'close-reveal-modal', //the class of a button or element that will close an open modal
}); }
- /
function sidenav() { $( '#dl-menu' ).dlmenu(); $($("#dl-menu button")[0]).trigger("click"); }
function ini() {
//alert("sd");
$(".dl-menu").each(function() {
$(this).hide();
});
$($(".dl-menu")[0]).show();
$("#tipImg").hide();
$($(".dl-menu")[0]).show();
var currentHash = $.locationHash();
//getPage(); //routeTree(); navigationSet();
jQueryHash();
flexnavi();
//Tips();
setTimeout(fixscroll, 10);
setTimeout(Tips, 50);
linkHome();
//imgbox();
navigation();
//modal();
sidenav();
top();
}
ini();
});