Difference between revisions of "Template:Fudan/js.js"

(Undo revision 234649 by Ripple (talk))
m (scrollspy fix)
 
(32 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
//Sidenav Init
 
//Sidenav Init
$(document).ready(function(){
+
$(function(){
 
     $('.sidenav').sidenav({
 
     $('.sidenav').sidenav({
 
         edge:'right',
 
         edge:'right',
Line 9: Line 9:
  
 
//Slider Init (Index Only)
 
//Slider Init (Index Only)
$(document).ready(function(){
+
$(function(){
 
     $('.slider').slider({
 
     $('.slider').slider({
 
         height: 400
 
         height: 400
Line 24: Line 24:
  
 
//Floating Btn Init
 
//Floating Btn Init
$(document).ready(function(){
+
$(function(){
 
     $('.fixed-action-btn').floatingActionButton();
 
     $('.fixed-action-btn').floatingActionButton();
 
});
 
});
  
 
//Tabs Init
 
//Tabs Init
$(document).ready(function(){
+
$(function(){
 
     $('.tabs').tabs();
 
     $('.tabs').tabs();
 
});
 
});
  
$(document).ready(function(){
+
$(function(){
 
     $('.tap-target').tapTarget();
 
     $('.tap-target').tapTarget();
 
});
 
});
  
 
//Collapsible Init
 
//Collapsible Init
$(document).ready(function(){
+
$(function(){
 
     $('.collapsible').collapsible({});
 
     $('.collapsible').collapsible({});
 
});
 
});
  
 
//ScrollSpy Init
 
//ScrollSpy Init
$(document).ready(function(){
+
$(function(){
    $('.scrollspy').scrollSpy();
+
  //$('.scrollspy').scrollSpy();  // not good for reader view
 +
  $('.scrolSpy').scrollSpy();
 
});
 
});
  
  
 
 
//Let's "fix" the navigator!!
 
var $topNav=$('#topNav');
 
var $pageContentNav=$('#pageContentNav');
 
var scrollTop=$(document).scrollTop();
 
var footerLocation=$("#FudanFooter").offset().top-scrollTop;
 
var pageContentNavHeight=$pageContentNav.height();
 
var bannerHeight=$('#contentBanner').height();
 
//init
 
//topNav
 
if(scrollTop<18){$topNav.css('top',18-scrollTop);}
 
else {$topNav.css('top',0);}
 
//pageContentNav
 
if(footerLocation<152+pageContentNavHeight){
 
    $pageContentNav.css('top',footerLocation-pageContentNavHeight-20);
 
}
 
else if(bannerHeight+180-scrollTop>132){
 
    $pageContentNav.css('top',bannerHeight+180-scrollTop);
 
}
 
else{
 
    $pageContentNav.css('top',132);
 
}
 
$(document).on('scroll',function () {
 
    scrollTop=$(document).scrollTop();
 
    footerLocation=$("#FudanFooter").offset().top-scrollTop;
 
    pageContentNavHeight=$pageContentNav.height();
 
    bannerHeight=$('#contentBanner').height();
 
    //topNav
 
    if(scrollTop<18){$topNav.css('top',18-scrollTop);}
 
    else {$topNav.css('top',0);}
 
    //pageContentNav
 
    if(footerLocation<152+pageContentNavHeight){
 
        $pageContentNav.css('top',footerLocation-pageContentNavHeight-20);
 
    }
 
    else if(bannerHeight+180-scrollTop>132){
 
        $pageContentNav.css('top',bannerHeight+180-scrollTop);
 
    }
 
    else{
 
        $pageContentNav.css('top',132);
 
    }
 
});
 
  
  
Line 107: Line 66:
 
     }
 
     }
  
     $(document).ready(function () {
+
     $(function () {
 
         setTimeout('sponsorsImgAlignment()', 2000);
 
         setTimeout('sponsorsImgAlignment()', 2000);
 
         sponsorsImgAlignment();
 
         sponsorsImgAlignment();
Line 119: Line 78:
  
 
//Init slide-out nav
 
//Init slide-out nav
$(document).ready(function () {
+
$(function () {
 
     $('#slide-out .collapsible-body').css('display','none');
 
     $('#slide-out .collapsible-body').css('display','none');
 
     $('#slide-out .collapsible li').removeClass('active');
 
     $('#slide-out .collapsible li').removeClass('active');
Line 125: Line 84:
  
 
//Parallax Init
 
//Parallax Init
$(document).ready(function(){
+
$(function(){
 
     $('.parallax').parallax();
 
     $('.parallax').parallax();
 
});
 
});
  
//Homepage figDescription
 
var $dropdown = $("#nav-mobile");
 
var $dropdown1 = $("#nav-mobile>li:eq(0)");
 
var $dropdown2 = $("#nav-mobile>li:eq(1)");
 
var $figDescription = $("#figDescription");
 
var $figDescriptionCard = $("#figDescription .card .card-content p");
 
var $dropdown1Li1 = $("#dropdown1>li:eq(0)");
 
var $dropdown1Li2 = $("#dropdown1>li:eq(1)");
 
$dropdown.mouseover(function () {
 
    $figDescription.css("display","block");
 
    $dropdown1.mouseover(function () {
 
        $figDescription.css("background","url(\"https://static.igem.org/mediawiki/2018/0/01/Main_page_welcome.png\")  no-repeat center center");
 
        $figDescription.css("background-size","auto 100%");
 
        $dropdown1Li1.mouseover(function () {
 
            $figDescriptionCard.text("111111111111111");
 
        });
 
        $dropdown1Li2.mouseover(function () {
 
            $figDescriptionCard.text("222222222222222");
 
        });
 
    });
 
    $dropdown2.mouseover(function () {
 
        $figDescription.css("background","url(\"https://static.igem.org/mediawiki/2017/1/19/Welcome_banner_website.jpg\") no-repeat center center");
 
        $figDescription.css("background-size","auto 100%");
 
    });
 
});
 
$dropdown.mouseout(function () {
 
    $figDescription.css("display","none");
 
});
 
 
 
 
//Where am I? Setting cookies!
 
function SetCookie(sName, sValue) {
 
    date = new Date();
 
    s = date.getDate();
 
    date.setDate(s + 1);            //expire time is one month late!, and can't be current date!
 
    document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
 
}
 
function GetCookie(sName)
 
{
 
    // cookies are separated by semicolons
 
    var aCookie = document.cookie.split("; ");
 
    for (var i=0; i < aCookie.length; i++)
 
    {
 
        // a name/value pair (a crumb) is separated by an equal sign
 
        var aCrumb = aCookie[i].split("=");
 
        if (sName == aCrumb[0]) {
 
            return unescape(aCrumb[1]);}
 
    }
 
    // a cookie with the requested name does not exist
 
    return null;
 
}
 
function fnLoad()
 
{
 
    document.documentElement.scrollTop = GetCookie("scrollTop");
 
}
 
function fnUnload()
 
{
 
    SetCookie("scrollTop", document.documentElement.scrollTop);
 
}
 
window.onload = fnLoad;
 
window.onunload = fnUnload;
 
  
  
Line 209: Line 106:
 
var $acknowledgementPhotoImg2=$("#acknowledgementPhoto>div.row:eq(1)>div");
 
var $acknowledgementPhotoImg2=$("#acknowledgementPhoto>div.row:eq(1)>div");
 
var $acknowledgementPhotoImg3=$("#acknowledgementPhoto>div.row:eq(2)>div");
 
var $acknowledgementPhotoImg3=$("#acknowledgementPhoto>div.row:eq(2)>div");
var acknowledgementPhotoImgWidth1=$acknowledgementPhotoImg1.eq(0).width()
+
var acknowledgementPhotoImgWidth1=$acknowledgementPhotoImg1.eq(0).width();
 
var acknowledgementPhotoImgWidth2=$acknowledgementPhotoImg2.eq(0).width();
 
var acknowledgementPhotoImgWidth2=$acknowledgementPhotoImg2.eq(0).width();
 
var acknowledgementPhotoImgWidth3=$acknowledgementPhotoImg3.eq(0).width();
 
var acknowledgementPhotoImgWidth3=$acknowledgementPhotoImg3.eq(0).width();
Line 240: Line 137:
 
     });
 
     });
 
});
 
});
 +
 +
 +
 +
 +
 +
//reset figurebanner height
 +
var $figureBanner=$(".figureBanner");
 +
var $figureBannerImg=$(".figureBanner img");
 +
 +
if($(window).width()>=1100 && $(window).width()>$(window).height()){
 +
    $figureBanner.css("height",$(window).height()-75);
 +
}
 +
else if($(window).width()>=600){
 +
    $figureBanner.css("height",400);
 +
}
 +
$(window).resize(function () {
 +
    if($(window).width()>=1100 && $(window).width()>$(window).height()){
 +
        $figureBanner.css("height",$(window).height()-75);
 +
    }
 +
    else if($(window).width()>=600){
 +
        $figureBanner.css("height",400);
 +
    }
 +
});
 +
 +
 +
 +
//Let's "fix" the navigator!!
 +
var pageNavAdjust=45;
 +
$(function () {
 +
var $topNav=$('#topNav');
 +
var $pageContentNav=$('#pageContentNav');
 +
var scrollTop=$(document).scrollTop();
 +
var footerLocation=$("#FudanFooter").offset().top-scrollTop;
 +
var pageContentNavHeight=$pageContentNav.height();
 +
var bannerHeight=$('#contentBanner').height();
 +
//init
 +
    if(0){
 +
 +
//topNav
 +
        if(scrollTop<18){$topNav.css('top',18-scrollTop);}
 +
        else {$topNav.css('top',0);}
 +
    }
 +
//pageContentNav
 +
if(footerLocation<172+pageContentNavHeight){
 +
    $pageContentNav.css('top',footerLocation-pageContentNavHeight-40);
 +
}
 +
else if(bannerHeight+180-scrollTop+pageNavAdjust>132){
 +
    $pageContentNav.css('top',bannerHeight+180-scrollTop+pageNavAdjust);
 +
}
 +
else{
 +
    $pageContentNav.css('top',132);
 +
}
 +
$(document).on('scroll',function () {
 +
    scrollTop=$(document).scrollTop();
 +
    footerLocation=$("#FudanFooter").offset().top-scrollTop;
 +
    pageContentNavHeight=$pageContentNav.height();
 +
    bannerHeight=$('#contentBanner').height();
 +
    if(0){
 +
        //topNav
 +
        if(scrollTop<18){$topNav.css('top',18-scrollTop);}
 +
        else {$topNav.css('top',0);}
 +
    }
 +
    //pageContentNav
 +
    if(footerLocation<172+pageContentNavHeight){
 +
        $pageContentNav.css('top',footerLocation-pageContentNavHeight-40);
 +
    }
 +
    else if(bannerHeight+180-scrollTop+pageNavAdjust>132){
 +
        $pageContentNav.css('top',bannerHeight+180-scrollTop+pageNavAdjust);
 +
    }
 +
    else{
 +
        $pageContentNav.css('top',132);
 +
    }
 +
});
 +
});
 +
 +
 +
 +
//Hide floating btn!
 +
var $floatingBtn=$(".floatingBtn");
 +
scrollTop=$(document).scrollTop();
 +
function hideFloatingBtn(a) {
 +
    if(a<200){
 +
        $floatingBtn.fadeOut(200);
 +
    }
 +
    else{
 +
        $floatingBtn.fadeIn(200);
 +
    }
 +
}
 +
hideFloatingBtn(scrollTop);
 +
$(document).on("scroll",function () {
 +
    scrollTop=$(document).scrollTop();
 +
    hideFloatingBtn(scrollTop);
 +
});
 +
 +
 +
 +
//gallery
 +
var $galleryActive=$(".galleryActive > img");
 +
var $galleryThumbnail=$(".galleryThumbnail");
 +
var $galleryThumbnailImg=$(".galleryThumbnail > img");
 +
var $galleryBtnLeft=$(".galleryBtnLeft");
 +
var $galleryBtnRight=$(".galleryBtnRight");
 +
var galleryThumbnailScrollLeft=$galleryThumbnail.eq(0).scrollLeft();
 +
var galleryThumbnailWidth=$galleryThumbnail.eq(0).width();
 +
$galleryThumbnailImg.click(function () {
 +
    $galleryThumbnailImg.animate({opacity:0.7},200);
 +
    $(this).animate({opacity:1},200);
 +
    $galleryActive.attr("src",$(this).attr("src"));
 +
});
 +
$galleryBtnLeft.click(function () {
 +
    galleryThumbnailScrollLeft=$galleryThumbnail.eq(0).scrollLeft();
 +
    galleryThumbnailWidth=$galleryThumbnail.eq(0).width();
 +
    $galleryThumbnail.animate({scrollLeft:galleryThumbnailScrollLeft-galleryThumbnailWidth*0.8},500);
 +
});
 +
$galleryBtnRight.click(function () {
 +
    galleryThumbnailScrollLeft=$galleryThumbnail.eq(0).scrollLeft();
 +
    galleryThumbnailWidth=$galleryThumbnail.eq(0).width();
 +
    $galleryThumbnail.animate({scrollLeft:galleryThumbnailScrollLeft+galleryThumbnailWidth*0.8},500);
 +
});
 +
 +
//hide the nav
 +
var $topNav=$("#topNav");
 +
var footerHeight=$("#FudanFooter").height();
 +
var pageHeight=$("#FudanWrapper").height();
 +
scrollTop=$(document).scrollTop();
 +
if(scrollTop>pageHeight-footerHeight-$(window).height() && $(window).width()>991){
 +
    $topNav.fadeOut(200);
 +
}
 +
else {
 +
    $topNav.fadeIn(200);
 +
}
 +
$(document).on("scroll",function () {
 +
    footerHeight=$("#FudanFooter").height();
 +
    pageHeight=$("#FudanWrapper").height();
 +
    scrollTop=$(document).scrollTop();
 +
    if(scrollTop>pageHeight-footerHeight-$(window).height() && $(window).width()>991){
 +
        $topNav.fadeOut(200);
 +
    }
 +
    else {
 +
        $topNav.fadeIn(200);
 +
    }
 +
});
 +
 +
 +
if(0){
 +
    //scroll down
 +
    scrollTop=$(document).scrollTop();
 +
    var t=scrollTop;
 +
    bannerHeight=$('#contentBanner').height();
 +
    $(function () {
 +
        $(document).on("scroll",function () {
 +
            if($(window).width()>600){
 +
                scrollTop=$(document).scrollTop();
 +
                bannerHeight=$('#contentBanner').height();
 +
                if (scrollTop<100 && scrollTop>t){
 +
                    t=bannerHeight+75;
 +
                    $("html").animate({scrollTop:bannerHeight+75},500);
 +
                }
 +
                else {
 +
                    t=scrollTop;
 +
                }
 +
            }
 +
        });
 +
    });
 +
}

Latest revision as of 17:46, 6 November 2018

//Sidenav Init $(function(){

   $('.sidenav').sidenav({
       edge:'right',
       inDuration: 250,
       outDuration: 350
   });

});

//Slider Init (Index Only) $(function(){

   $('.slider').slider({
       height: 400
   });

});

//Dropdown Init $(".dropdown-trigger").dropdown({

   coverTrigger: false,
   hover: true,
   inDuration: 250,
   outDuration: 350

});

//Floating Btn Init $(function(){

   $('.fixed-action-btn').floatingActionButton();

});

//Tabs Init $(function(){

   $('.tabs').tabs();

});

$(function(){

   $('.tap-target').tapTarget();

});

//Collapsible Init $(function(){

   $('.collapsible').collapsible({});

});

//ScrollSpy Init $(function(){

 //$('.scrollspy').scrollSpy();  // not good for reader view
 $('.scrolSpy').scrollSpy();

});




if(0) {

//align sponsors img

   var $sponsors = $('.sponsors');
   var sponsor0Height = $sponsors.eq(0).height();
   function sponsorsImgAlignment() {
       sponsor0Height = $sponsors.eq(0).height();
       for (var i = 1; i < $sponsors.length; i++) {
           $sponsors.eq(i).css('margin-top', 0.5 * (sponsor0Height - $sponsors.eq(i).height()) + 5);
       }
   }
   $(function () {
       setTimeout('sponsorsImgAlignment()', 2000);
       sponsorsImgAlignment();
       $(window).resize(function () {
           sponsorsImgAlignment();
       });
   });

}


//Init slide-out nav $(function () {

   $('#slide-out .collapsible-body').css('display','none');
   $('#slide-out .collapsible li').removeClass('active');

});

//Parallax Init $(function(){

   $('.parallax').parallax();

});



//Abstract on Content Page var $abstractBtn=$("#abstractBtn"); var $abstractContentCloseBtn=$("#abstractContent > a:eq(0)"); var $abstractContent=$("#abstractContent"); $abstractBtn.click(function () {

   $abstractContent.toggle();
   $abstractContentCloseBtn.click(function () {
       $abstractContent.css('display','none');
   });

});

//Acknowledgement Photo adjust var $acknowledgementPhotoImg1=$("#acknowledgementPhoto>div.row:eq(0)>div"); var $acknowledgementPhotoImg2=$("#acknowledgementPhoto>div.row:eq(1)>div"); var $acknowledgementPhotoImg3=$("#acknowledgementPhoto>div.row:eq(2)>div"); var acknowledgementPhotoImgWidth1=$acknowledgementPhotoImg1.eq(0).width(); var acknowledgementPhotoImgWidth2=$acknowledgementPhotoImg2.eq(0).width(); var acknowledgementPhotoImgWidth3=$acknowledgementPhotoImg3.eq(0).width(); $acknowledgementPhotoImg1.css("height",acknowledgementPhotoImgWidth1*1.35); $acknowledgementPhotoImg2.css("height",acknowledgementPhotoImgWidth1); $acknowledgementPhotoImg3.css("height",acknowledgementPhotoImgWidth3*0.38); $(window).resize(function () {

   acknowledgementPhotoImgWidth1=$acknowledgementPhotoImg1.eq(0).width();
   acknowledgementPhotoImgWidth3=$acknowledgementPhotoImg3.eq(0).width();
   $acknowledgementPhotoImg1.css("height",acknowledgementPhotoImgWidth1*1.4);
   $acknowledgementPhotoImg2.css("height",acknowledgementPhotoImgWidth1);
   $acknowledgementPhotoImg3.css("height",acknowledgementPhotoImgWidth3*0.38);

});


$acknowledgementPhotoImg1.mouseover(function () {

   $(this).children("span").eq(0).css("display","inherit");
   $(this).children("span").eq(0).css("width",acknowledgementPhotoImgWidth1);
   $acknowledgementPhotoImg1.mouseout(function () {
       $(this).children("span").eq(0).css("display","none");
   });

}); $acknowledgementPhotoImg2.mouseover(function () {

   $(this).children("span").eq(0).css("display","inherit");
   $(this).children("span").eq(0).css("width",acknowledgementPhotoImgWidth2);
   $acknowledgementPhotoImg2.mouseout(function () {
       $(this).children("span").eq(0).css("display","none");
   });

});



//reset figurebanner height var $figureBanner=$(".figureBanner"); var $figureBannerImg=$(".figureBanner img");

if($(window).width()>=1100 && $(window).width()>$(window).height()){

   $figureBanner.css("height",$(window).height()-75);

} else if($(window).width()>=600){

   $figureBanner.css("height",400);

} $(window).resize(function () {

   if($(window).width()>=1100 && $(window).width()>$(window).height()){
       $figureBanner.css("height",$(window).height()-75);
   }
   else if($(window).width()>=600){
       $figureBanner.css("height",400);
   }

});


//Let's "fix" the navigator!! var pageNavAdjust=45; $(function () { var $topNav=$('#topNav'); var $pageContentNav=$('#pageContentNav'); var scrollTop=$(document).scrollTop(); var footerLocation=$("#FudanFooter").offset().top-scrollTop; var pageContentNavHeight=$pageContentNav.height(); var bannerHeight=$('#contentBanner').height(); //init

   if(0){

//topNav

       if(scrollTop<18){$topNav.css('top',18-scrollTop);}
       else {$topNav.css('top',0);}
   }

//pageContentNav if(footerLocation<172+pageContentNavHeight){

   $pageContentNav.css('top',footerLocation-pageContentNavHeight-40);

} else if(bannerHeight+180-scrollTop+pageNavAdjust>132){

   $pageContentNav.css('top',bannerHeight+180-scrollTop+pageNavAdjust);

} else{

   $pageContentNav.css('top',132);

} $(document).on('scroll',function () {

   scrollTop=$(document).scrollTop();
   footerLocation=$("#FudanFooter").offset().top-scrollTop;
   pageContentNavHeight=$pageContentNav.height();
   bannerHeight=$('#contentBanner').height();
   if(0){
       //topNav
       if(scrollTop<18){$topNav.css('top',18-scrollTop);}
       else {$topNav.css('top',0);}
   }
   //pageContentNav
   if(footerLocation<172+pageContentNavHeight){
       $pageContentNav.css('top',footerLocation-pageContentNavHeight-40);
   }
   else if(bannerHeight+180-scrollTop+pageNavAdjust>132){
       $pageContentNav.css('top',bannerHeight+180-scrollTop+pageNavAdjust);
   }
   else{
       $pageContentNav.css('top',132);
   }

}); });


//Hide floating btn! var $floatingBtn=$(".floatingBtn"); scrollTop=$(document).scrollTop(); function hideFloatingBtn(a) {

   if(a<200){
       $floatingBtn.fadeOut(200);
   }
   else{
       $floatingBtn.fadeIn(200);
   }

} hideFloatingBtn(scrollTop); $(document).on("scroll",function () {

   scrollTop=$(document).scrollTop();
   hideFloatingBtn(scrollTop);

});


//gallery var $galleryActive=$(".galleryActive > img"); var $galleryThumbnail=$(".galleryThumbnail"); var $galleryThumbnailImg=$(".galleryThumbnail > img"); var $galleryBtnLeft=$(".galleryBtnLeft"); var $galleryBtnRight=$(".galleryBtnRight"); var galleryThumbnailScrollLeft=$galleryThumbnail.eq(0).scrollLeft(); var galleryThumbnailWidth=$galleryThumbnail.eq(0).width(); $galleryThumbnailImg.click(function () {

   $galleryThumbnailImg.animate({opacity:0.7},200);
   $(this).animate({opacity:1},200);
   $galleryActive.attr("src",$(this).attr("src"));

}); $galleryBtnLeft.click(function () {

   galleryThumbnailScrollLeft=$galleryThumbnail.eq(0).scrollLeft();
   galleryThumbnailWidth=$galleryThumbnail.eq(0).width();
   $galleryThumbnail.animate({scrollLeft:galleryThumbnailScrollLeft-galleryThumbnailWidth*0.8},500);

}); $galleryBtnRight.click(function () {

   galleryThumbnailScrollLeft=$galleryThumbnail.eq(0).scrollLeft();
   galleryThumbnailWidth=$galleryThumbnail.eq(0).width();
   $galleryThumbnail.animate({scrollLeft:galleryThumbnailScrollLeft+galleryThumbnailWidth*0.8},500);

});

//hide the nav var $topNav=$("#topNav"); var footerHeight=$("#FudanFooter").height(); var pageHeight=$("#FudanWrapper").height(); scrollTop=$(document).scrollTop(); if(scrollTop>pageHeight-footerHeight-$(window).height() && $(window).width()>991){

   $topNav.fadeOut(200);

} else {

   $topNav.fadeIn(200);

} $(document).on("scroll",function () {

   footerHeight=$("#FudanFooter").height();
   pageHeight=$("#FudanWrapper").height();
   scrollTop=$(document).scrollTop();
   if(scrollTop>pageHeight-footerHeight-$(window).height() && $(window).width()>991){
       $topNav.fadeOut(200);
   }
   else {
       $topNav.fadeIn(200);
   }

});


if(0){

   //scroll down
   scrollTop=$(document).scrollTop();
   var t=scrollTop;
   bannerHeight=$('#contentBanner').height();
   $(function () {
       $(document).on("scroll",function () {
           if($(window).width()>600){
               scrollTop=$(document).scrollTop();
               bannerHeight=$('#contentBanner').height();
               if (scrollTop<100 && scrollTop>t){
                   t=bannerHeight+75;
                   $("html").animate({scrollTop:bannerHeight+75},500);
               }
               else {
                   t=scrollTop;
               }
           }
       });
   });

}