Difference between revisions of "Template:DLUT China B/js/script.js"

(导航栏增加主页项。)
m
 
(6 intermediate revisions by the same user not shown)
Line 20: Line 20:
 
                 "name": "Demonstrate",
 
                 "name": "Demonstrate",
 
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Demonstrate"
 
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Demonstrate"
            },
 
            {
 
                "name": "Experiments",
 
                "link": "https://2018.igem.org/Team:DLUT_China_B/Experiments"
 
 
             },
 
             },
 
             {
 
             {
Line 37: Line 33:
 
     {
 
     {
 
         "menu": "Parts",
 
         "menu": "Parts",
         "subMenu": [
+
         "link": "https://2018.igem.org/Team:DLUT_China_B/Parts"
            {
+
                "name": "Parts Overview",
+
                "link": "https://2018.igem.org/Team:DLUT_China_B/PartsOverview"
+
            },
+
            {
+
                "name": "Basic Parts",
+
                "link": "https://2018.igem.org/Team:DLUT_China_B/BasicParts"
+
            },
+
            {
+
                "name": "Composite Parts",
+
                "link": "https://2018.igem.org/Team:DLUT_China_B/CompositeParts"
+
            }
+
        ]
+
 
     },
 
     },
 
     {
 
     {
Line 56: Line 39:
 
         "subMenu": [
 
         "subMenu": [
 
             {
 
             {
                 "name": "Condition Optimization",
+
                 "name": "Gray Value-Concentration Model",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/ConditionOptimization"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/GrayValueConcentrationModel"
 
             },
 
             },
 
             {
 
             {
                 "name": "Standard Curve",
+
                 "name": "Kinetic Model",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/StandardCurve"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/KineticModel"
 
             },
 
             },
 
             {
 
             {
                 "name": "Result",
+
                 "name": "Liquid Crystal Molecules Perturbations Model",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Result"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/LiquidCrystalMoleculesPerturbationsModel"
 
             }
 
             }
 
         ]
 
         ]
Line 74: Line 57:
 
             {
 
             {
 
                 "name": "Applied Design",
 
                 "name": "Applied Design",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/AppliedDesign"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Applied_Design"
 
             },
 
             },
 
             {
 
             {
 
                 "name": "Hardware",
 
                 "name": "Hardware",
 
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Hardware"
 
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Hardware"
            },
 
            {
 
                "name": "Software",
 
                "link": "https://2018.igem.org/Team:DLUT_China_B/Software"
 
 
             }
 
             }
 
         ]
 
         ]
 
     },
 
     },
 
     {
 
     {
         "menu": "Human Practice",
+
         "menu": "Human Practices",
 
         "subMenu": [
 
         "subMenu": [
 
             {
 
             {
                 "name": "Human Practice",
+
                 "name": "Human Practices",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/HumanPractice"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Human_Practices"
 
             },
 
             },
 
             {
 
             {
                 "name": "Education",
+
                 "name": "Public Engagement",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Education"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Public_Engagement"
 
             }
 
             }
 
         ]
 
         ]
Line 111: Line 90:
 
             },
 
             },
 
             {
 
             {
                 "name": "Collaboration",
+
                 "name": "Collaborations",
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Collaboration"
+
                 "link": "https://2018.igem.org/Team:DLUT_China_B/Collaborations"
 
             }
 
             }
 
         ]
 
         ]
Line 119: Line 98:
 
let ul = document.createElement("ul");
 
let ul = document.createElement("ul");
 
ul.setAttribute("class", "menu");
 
ul.setAttribute("class", "menu");
let home=document.createElement("li");
+
for (let i = 0; i < navData.length; ++i) {
let homeName=document.createElement("a");
+
homeName.innerText=navData[0]["menu"];
+
homeName.setAttribute("href",navData[0]["link"]);
+
home.appendChild(homeName);
+
ul.appendChild(home);
+
for (let i = 1; i < navData.length; ++i) {
+
 
     let menu = document.createElement("li");
 
     let menu = document.createElement("li");
 
     let menuName = document.createElement("a");
 
     let menuName = document.createElement("a");
 
     menuName.innerText = navData[i]["menu"];
 
     menuName.innerText = navData[i]["menu"];
     let subMenu = document.createElement("ul");
+
 
    subMenu.setAttribute("class", "subMenu");
+
     if(navData[i].hasOwnProperty("subMenu")) {
    for (let j = 0; j < navData[i]["subMenu"].length; ++j) {
+
        let subMenu = document.createElement("ul");
        let subMenuName = document.createElement("li");
+
        subMenu.setAttribute("class", "subMenu");
        let subMenuNameA = document.createElement("a");
+
        for (let j = 0; j < navData[i]["subMenu"].length; ++j) {
        subMenuNameA.innerText = navData[i]["subMenu"][j]["name"];
+
            let subMenuName = document.createElement("li");
        subMenuNameA.setAttribute("href", navData[i]["subMenu"][j]["link"]);
+
            let subMenuNameA = document.createElement("a");
        subMenuName.appendChild(subMenuNameA);
+
            subMenuNameA.innerText = navData[i]["subMenu"][j]["name"];
        subMenu.appendChild(subMenuName);
+
            subMenuNameA.setAttribute("href", navData[i]["subMenu"][j]["link"]);
 +
            subMenuName.appendChild(subMenuNameA);
 +
            subMenu.appendChild(subMenuName);
 +
        }
 +
        menu.appendChild(menuName);
 +
        menu.appendChild(subMenu);
 +
    }
 +
    else {
 +
        menuName.setAttribute("href", navData[i]["link"]);
 +
        menu.appendChild(menuName);
 
     }
 
     }
    menu.appendChild(menuName);
 
    menu.appendChild(subMenu);
 
 
     ul.appendChild(menu);
 
     ul.appendChild(menu);
 
}
 
}
Line 147: Line 127:
 
/*至顶按钮*/
 
/*至顶按钮*/
 
$('#back').click(function () {
 
$('#back').click(function () {
     $('html').animate( {scrollTop: 0}, 500);
+
     if(navigator.userAgent.indexOf("Edge")>-1)
 +
        $('body').animate( {scrollTop: 0}, 500);
 +
    else
 +
        $('html').animate( {scrollTop: 0}, 500);
 
});
 
});
document.onscroll=function () {
+
function topToggle() {
     if($('html').scrollTop()>600)
+
     if($(window).scrollTop()>600)
 
         document.getElementById("back").style.display="block";
 
         document.getElementById("back").style.display="block";
 
     else
 
     else
 
         document.getElementById("back").style.display="none";
 
         document.getElementById("back").style.display="none";
};
+
}

Latest revision as of 23:37, 17 October 2018

/*导航栏*/ let nav = document.getElementById("nav"); let navData = [

   {
       "menu": "Home",
       "link": "https://2018.igem.org/Team:DLUT_China_B"
   },
   {
       "menu": "Project",
       "subMenu": [
           {
               "name": "Description",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Description"
           },
           {
               "name": "Design",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Design"
           },
           {
               "name": "Demonstrate",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Demonstrate"
           },
           {
               "name": "InterLab",
               "link": "https://2018.igem.org/Team:DLUT_China_B/InterLab"
           },
           {
               "name": "Notebook",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Notebook"
           }
       ]
   },
   {
       "menu": "Parts",
       "link": "https://2018.igem.org/Team:DLUT_China_B/Parts"
   },
   {
       "menu": "Model",
       "subMenu": [
           {
               "name": "Gray Value-Concentration Model",
               "link": "https://2018.igem.org/Team:DLUT_China_B/GrayValueConcentrationModel"
           },
           {
               "name": "Kinetic Model",
               "link": "https://2018.igem.org/Team:DLUT_China_B/KineticModel"
           },
           {
               "name": "Liquid Crystal Molecules Perturbations Model",
               "link": "https://2018.igem.org/Team:DLUT_China_B/LiquidCrystalMoleculesPerturbationsModel"
           }
       ]
   },
   {
       "menu": "Awards",
       "subMenu": [
           {
               "name": "Applied Design",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Applied_Design"
           },
           {
               "name": "Hardware",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Hardware"
           }
       ]
   },
   {
       "menu": "Human Practices",
       "subMenu": [
           {
               "name": "Human Practices",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Human_Practices"
           },
           {
               "name": "Public Engagement",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Public_Engagement"
           }
       ]
   },
   {
       "menu": "Team",
       "subMenu": [
           {
               "name": "Team Members",
               "link": "https://2018.igem.org/Team:DLUT_China_B/TeamMembers"
           },
           {
               "name": "Attributions",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Attributions"
           },
           {
               "name": "Collaborations",
               "link": "https://2018.igem.org/Team:DLUT_China_B/Collaborations"
           }
       ]
   }

]; let ul = document.createElement("ul"); ul.setAttribute("class", "menu"); for (let i = 0; i < navData.length; ++i) {

   let menu = document.createElement("li");
   let menuName = document.createElement("a");
   menuName.innerText = navData[i]["menu"];
   if(navData[i].hasOwnProperty("subMenu")) {
       let subMenu = document.createElement("ul");
       subMenu.setAttribute("class", "subMenu");
       for (let j = 0; j < navData[i]["subMenu"].length; ++j) {
           let subMenuName = document.createElement("li");
           let subMenuNameA = document.createElement("a");
           subMenuNameA.innerText = navData[i]["subMenu"][j]["name"];
           subMenuNameA.setAttribute("href", navData[i]["subMenu"][j]["link"]);
           subMenuName.appendChild(subMenuNameA);
           subMenu.appendChild(subMenuName);
       }
       menu.appendChild(menuName);
       menu.appendChild(subMenu);
   }
   else {
       menuName.setAttribute("href", navData[i]["link"]);
       menu.appendChild(menuName);
   }
   ul.appendChild(menu);

} document.getElementById('nav').appendChild(ul);

/*至顶按钮*/ $('#back').click(function () {

   if(navigator.userAgent.indexOf("Edge")>-1)
       $('body').animate( {scrollTop: 0}, 500);
   else
       $('html').animate( {scrollTop: 0}, 500);

}); function topToggle() {

   if($(window).scrollTop()>600)
       document.getElementById("back").style.display="block";
   else
       document.getElementById("back").style.display="none";

}