Difference between revisions of "Template:BNU-China/Javascript/index"

(Created page with "var navWidth; var navFontSize; var navTop; var idStoryMax=8; var idStory=0; $(document).ready(function(){ $("#top_title").hide(); $("#sideMenu").hide(); <!--首页故事-->...")
 
Line 2: Line 2:
 
var navFontSize;
 
var navFontSize;
 
var navTop;
 
var navTop;
var idStoryMax=8;
 
var idStory=0;
 
 
$(document).ready(function(){
 
$(document).ready(function(){
 +
<!--导航栏自适应-->
 
$("#top_title").hide();
 
$("#top_title").hide();
 
$("#sideMenu").hide();
 
$("#sideMenu").hide();
<!--首页故事-->
+
if($(window).width()>=480){
if($(window).width()>=767)
+
{
+
$(".w_indexPhoto").hide();
+
$("#story0").show();
+
}
+
$("#storyArrow").click(function(){
+
if(idStory<idStoryMax){
+
$("html,body").animate({"scrollTop":0},800);
+
$("#story"+String(idStory)).slideUp(800,'swing');
+
idStory=idStory+1;
+
$("#story"+String(idStory)).show();
+
}
+
});
+
 
+
$("#storyArrow").hover(function(){
+
$(this).animate({"top":"+=2%"},500,"swing");
+
},function(){
+
$(this).animate({"top":"-=2%"},500,"swing");
+
});
+
 
+
function handleMouseScroll(e) {
+
if($(window).width()>=767)
+
{
+
if(e.wheelDelta<0){
+
if(idStory<idStoryMax){
+
if($(document).scrollTop()>=0.8*($(document).height()-$(window).height()))
+
{
+
window.onmousewheel =0;
+
$("html,body").animate({"scrollTop":0},800);
+
$("#story"+String(idStory)).slideUp(800,'swing',function(){window.onmousewheel = handleMouseScroll;});
+
idStory=idStory+1;
+
$("#story"+String(idStory)).show();
+
if(idStory==idStoryMax) $("#storyArrow").hide();
+
}
+
}
+
}
+
else{
+
if($(window).scrollTop()==0)
+
{
+
if(idStory>0)
+
{
+
window.onmousewheel =0;
+
$("html,body").animate({"scrollTop":0},800);
+
idStory=idStory-1;
+
$("#story"+String(idStory)).slideDown(800,'swing',function(){$("#story"+String(idStory+1)).hide();window.onmousewheel = handleMouseScroll;});
+
}
+
if(idStory<idStoryMax) $("#storyArrow").show();
+
}
+
}
+
}
+
}
+
// window.onmousewheel = document.onmousewheel = handleMouseScroll;
+
window.onmousewheel = handleMouseScroll;
+
 
+
if($(window).width()<=767){
+
$("#storyArrow").hide();
+
}
+
<!--导航栏自适应-->
+
if($(window).width()>=480){
+
 
$("#w_nav>div").hide();
 
$("#w_nav>div").hide();
 
}
 
}
Line 74: Line 14:
 
}
 
}
 
$("#w_nav>ul>li>a").css({"width":$(window).width()/7-10,"font-size":$(window).width()/1280*25});
 
$("#w_nav>ul>li>a").css({"width":$(window).width()/7-10,"font-size":$(window).width()/1280*25});
$("#w_nav>ul").css({"top":$(window).width()/1280*(-55)});
+
$("#w_nav>ul").css({"top":$(window).width()/1280*(-41)});
$("#w_nav>div>ul").css({"top":$(window).width()/1280*(-55)});
+
$("#w_nav>div>ul").css({"top":$(window).width()/1280*(-41)});
 
navWidth=$(window).width();
 
navWidth=$(window).width();
 
navFontSize=$("#w_nav>ul>li>a").css("font-size");
 
navFontSize=$("#w_nav>ul>li>a").css("font-size");
Line 100: Line 40:
 
var x=$(this).data("id");
 
var x=$(this).data("id");
 
$('html').animate({scrollTop:$(x).offset().top-$("#w_nav").height()*2/3},500);
 
$('html').animate({scrollTop:$(x).offset().top-$("#w_nav").height()*2/3},500);
});
+
});
<!--悟空眼睛-->
+
<!--悟空眼睛-->
 
$(document).mousemove(function(e){
 
$(document).mousemove(function(e){
 
   var x=$("#eye").width()/2;
 
   var x=$("#eye").width()/2;
Line 110: Line 50:
 
});
 
});
 
<!--导航栏首页故事自适应-->
 
<!--导航栏首页故事自适应-->
$(window).resize(function(){
+
$(window).resize(function(){
if($(window).width()<=767){
+
$("#storyArrow").hide();
+
$(".w_indexPhoto").show();
+
}
+
else{
+
$("#storyArrow").show();
+
$(".w_indexPhoto").hide();
+
$("#story"+String(idStory)).show();
+
}
+
 
if($(window).width()>=480){
 
if($(window).width()>=480){
 
$("#w_nav>div").hide();
 
$("#w_nav>div").hide();
Line 135: Line 66:
 
$("#w_nav>div>ul").hide();
 
$("#w_nav>div>ul").hide();
 
}
 
}
 
 
 
});
 
});

Revision as of 02:20, 7 October 2017

var navWidth; var navFontSize; var navTop; $(document).ready(function(){ $("#top_title").hide(); $("#sideMenu").hide(); if($(window).width()>=480){ $("#w_nav>div").hide(); } if($(window).width()<480){ $("#w_nav>ul").hide(); $("#w_nav>div>ul").hide(); } $("#w_nav>ul>li>a").css({"width":$(window).width()/7-10,"font-size":$(window).width()/1280*25}); $("#w_nav>ul").css({"top":$(window).width()/1280*(-41)}); $("#w_nav>div>ul").css({"top":$(window).width()/1280*(-41)}); navWidth=$(window).width(); navFontSize=$("#w_nav>ul>li>a").css("font-size"); navTop=$("#w_nav>ul").css("top");

$("#w_nav>div>p").click(function(){ $("#w_nav>div>ul").slideToggle(); }); $("#w_menu>li>ul").hide().click(function(event){ event.stopPropagation(); });

$("#w_menu>li").click(function(){ var menuFlag=true; if($(this).find('ul').is(":visible")) menuFlag=false; $("#w_menu>li>ul:visible").slideUp(); if(menuFlag) $(this).find('ul').slideToggle(); });

$("#w_menu>li>ul>li>p").click(function(){ var x=$(this).data("id"); $('html').animate({scrollTop:$(x).offset().top-$("#w_nav").height()*2/3},500); }); $(document).mousemove(function(e){

 var x=$("#eye").width()/2;
 var y=$("#eye").height()/2;
 $("#eye").css({"left":parseFloat(String((e.pageX-x)/100)),"top":parseFloat(String((e.pageY-$(window).scrollTop()-y)/100))});

});

}); $(window).resize(function(){ if($(window).width()>=480){ $("#w_nav>div").hide(); $("#w_nav>ul").show(); $("#w_nav>ul>li>a").css({"width":$(window).width()/7-10,"font-size":parseFloat(navFontSize)*parseFloat(String($(window).width()))/parseFloat(String(navWidth)),"top":parseFloat(navTop)*parseFloat(String($(window).width()))/parseFloat(String(navWidth))}); $("#w_nav>ul").css({"top":parseFloat(navTop)*parseFloat(String($(window).width()))/parseFloat(String(navWidth))}); $("#w_nav>div>ul").css({"top":parseFloat(navTop)*parseFloat(String($(window).width()))/parseFloat(String(navWidth))}); navWidth=$(window).width(); navFontSize=$("#w_nav>ul>li>a").css("font-size"); navTop=$("#w_nav>ul").css("top"); } else{ $("#w_nav>ul").hide(); $("#w_nav>div").show(); $("#w_nav>div>ul").hide(); } });