Team:SYSU-China/Project.js

From 2013.igem.org

(Difference between revisions)
 
(6 intermediate revisions not shown)
Line 47: Line 47:
h2num = 0;
h2num = 0;
title.each(function() {
title.each(function() {
-
var anchor_num = $(this).offset().top;
+
var anchor_num = "h2_"+ number;
$(this).attr("id","h2_"+number);
$(this).attr("id","h2_"+number);
var id=$('#h2_'+ number);
var id=$('#h2_'+ number);
Line 68: Line 68:
$("#side_bar").html( tag );
$("#side_bar").html( tag );
-
$("#side_bar p").click(function(){
 
-
title = $(".chapter h1,.chapter h2");
 
-
number = 0;
 
-
tag = "";
 
-
h2num = 0;
 
-
title.each(function() {
 
-
var anchor_num = $(this).offset().top;
 
-
$(this).attr("id","h2_"+number);
 
-
var id=$('#h2_'+ number);
 
-
text = $(this).text();
 
-
if(new RegExp(":").test(text)) {
 
-
title=text.split(":");
 
-
text = title[0];
 
-
};
 
-
if ($(this).attr('tagName') == "H1") //不可用"h1"
 
-
{
 
-
h2num = h2num + 1;
 
-
tag = tag + "<div class='anchor-h2' id= 'h2num_"+h2num+"'><p class='" + anchor_num + "' >" + text + "</p></div>";
 
-
}
 
-
else {
 
-
tag = tag +"<div class='anchor-h3 h2num_"+h2num+"' id= 'id_"+number+"'><p class='" + anchor_num + "' >"+ text +"</p></div>";
 
-
}
 
-
number = number + 1;
 
-
});
 
-
num_max = number-1;
 
-
$("#side_bar").html( tag );
 
-
});
 
/*SIDE_BAR LINK*/
/*SIDE_BAR LINK*/
$("#side_bar p").click(function(){
$("#side_bar p").click(function(){
-
var anchor_num = $(this).attr("class");
+
var id=$(this).attr("class");
 +
var anchor_num = $("#"+id).offset().top;
$('body,html').animate({scrollTop:anchor_num},500);
$('body,html').animate({scrollTop:anchor_num},500);
});
});

Latest revision as of 02:53, 29 October 2013

$(document).ready(function(){

/* TOPBUTTON_POSITION */

scr_position = 0; $("#top_button span").css({"left":$("div.content_body").offset().left+$("div.content_body").width(),"top":$(window).height()-177});

$("#top_button span").mouseenter(function(){ $("#top_button span").stop(); $("#top_button span").css({"background":"url(TOP_BACKING.png)"}); }); $("#top_button span").mouseout(function(){ $("#top_button span").css({"background":"url(WIKI-MASCOT-STAND-SHADOW.png)"}); }); $(window).scroll(function(){ if ( scr_position < $(window).scrollTop() ) { $("#top_button span").css({"background":"url(TOP_FALLING.png)"}); } else { $("#top_button span").css({"background":"url(TOP_BACKING.png)"}); }; scr_position = $(window).scrollTop(); $("#top_button span").animate({padding: "+=0px"},600,function(){ $("#top_button span").css({"background":"url(WIKI-MASCOT-STAND-SHADOW.png)"}); });

/*TOP BUTTON HANGING*/

if ($(window).scrollTop() + $(window).height() - $("#cont_column").height() -$("div.navigater").height() - $("#animat").height() > 20 &&$("#top_button span").css("position")=="fixed") { $("#top_button span").css({"position":"relative","top":$("#cont_column").height()-100,"left":$("#top_button").width()}); } else if ($(window).scrollTop() + $(window).height() - $("#cont_column").height() -$("div.navigater").height() - $("#animat").height() <=20 &&$("#top_button span").css("position")=="relative"){ $("#top_button span").css({"position":"fixed","top":$(window).height()-177,"left":$("div.content_body").offset().left+$("div.content_body").width()}); };

});


$("#top_button span").click(function(){ $('body,html').animate({scrollTop:0},500);

});


/* SIDE_TAG */ title = $(".chapter h1,.chapter h2"); number = 0; tag = ""; h2num = 0; title.each(function() { var anchor_num = "h2_"+ number; $(this).attr("id","h2_"+number); var id=$('#h2_'+ number); text = $(this).text(); if(new RegExp(":").test(text)) { title=text.split(":"); text = title[0]; }; if ($(this).attr('tagName') == "H1") //不可用"h1" { h2num = h2num + 1;

tag = tag + "

" + text + "

";

} else {

tag = tag +"

"+ text +"

";

} number = number + 1; }); num_max = number-1; $("#side_bar").html( tag );

/*SIDE_BAR LINK*/ $("#side_bar p").click(function(){ var id=$(this).attr("class"); var anchor_num = $("#"+id).offset().top; $('body,html').animate({scrollTop:anchor_num},500); });

/* FOLLOWING */ win_height = $(window).height(); number = 0; toptop = 145;

$(".anchor-h2 .anchor-h3").css("position","relative"); $(".anchor-h3").hide(); /*SLIDE DOWN*/ $(function(){ var feedback=0; $(".anchor-h2").mouseenter(function(event) { var h2num = $(this).attr("id"); event.preventDefault(); if (feedback==h2num) { $("."+h2num).slideToggle("fast",function(){feedback = h2num}); } else if (feedback!=h2num){ /*$(".anchor-h3").slideUp("fast");*/ $("."+h2num).slideDown("fast",function(){feedback = h2num;}); }; }); });

/*SIDE_BAR HANGING*/ scr_position_2 = 0; if ($(window).scrollTop() >= 185) { $("#side_bar").css({"position":"fixed","top":0}); left = $("div.chapter").offset().left - $("#side_bar").width(); $("#side_bar").css("left",left+1); } else if ($(window).scrollTop() < 185){ $("#side_bar").css({"position":"absolute","top":50}); left = $("div.chapter").offset().left - $("div.content_body").offset().left - $("#side_bar").width(); $("#side_bar").css("left",left+1); }; $(window).scroll(function(){ scr_position_2 = $(window).scrollTop(); if ($(window).scrollTop() >= 178 &&$("#side_bar").css("position")=="absolute") { $("#side_bar").css({"position":"fixed","top":0}); left = $("div.chapter").offset().left - $("#side_bar").width(); $("#side_bar").css("left",left+1); } else if ($(window).scrollTop() < 178 &&$("#side_bar").css("position")=="fixed"){ $("#side_bar").css({"position":"absolute","top":50}); left = $("div.chapter").offset().left - $("div.content_body").offset().left - $("#side_bar").width(); $("#side_bar").css("left",left+1);

};

});


});