Team:BIT/public.js

From 2014.igem.org

(Difference between revisions)
Line 41: Line 41:
/*返回顶部按钮*/
/*返回顶部按钮*/
-
(function(){
+
(function back(){
var scrollEle = clientEle = document.documentElement,
var scrollEle = clientEle = document.documentElement,
toTopBtn = document.getElementById("toTop"),
toTopBtn = document.getElementById("toTop"),

Revision as of 13:50, 21 August 2014

/*横向导航*/ $(document).ready(function(){ $(".nav li").mouseover(function(){ $(this).css("background","rgba(255,255,255,0.5)") }); $(".nav li").mouseout(function(){ $(this).css("background","none") }); }); /*横向二级导航*/ $(document).ready(function(){ $('ul.one').hide();

//Open Menu $('.nav li').hover( function(){ var openMenu= $(this).children('ul.one'); $(openMenu).show(); }, function(){ var openMenu= $(this).children('ul.one'); $(openMenu).hide(); });

//Open Sub Menu /* $('.one#sub-menu').css({ 'left':'80%', 'top':'0' }); $('.one li').hover( function(){ var subMenu=$(this).children('.one#sub-menu'); $(subMenu).css({ 'left':'100%', 'top':'10%', }) });*/


});

/*返回顶部按钮*/ (function back(){ var scrollEle = clientEle = document.documentElement, toTopBtn = document.getElementById("toTop"), compatMode = document.compatMode, isChrome = window.navigator.userAgent.indexOf("Chrome") === -1 ? false : true; //不同渲染模式以及Chrome的预处理 if(compatMode === "BackCompat" || isChrome){ scrollEle = document.body; } if(compatMode === "BackCompat"){ clientEle = document.body; } //返回顶部按钮的点击响应(注册函数),时间间隔和高度缩减率可以调节 toTopBtn.onclick = function(){ var moveInterval = setInterval(moveScroll, 10); function moveScroll(){ setScrollTop(getScrollTop() / 1.2); if(getScrollTop() === 0){ clearInterval(moveInterval); } } } //滚动时判断是否显示返回顶部按钮(注册函数) window.onscroll = function(){ var display = toTopBtn.style.display; if(getScrollTop() > 0){ if(display === "none" || display === ""){ toTopBtn.style.display = "block"; } }else{ if(display === "block" || display === ""){ toTopBtn.style.display = "none"; } } } //获取和设置scrollTop function getScrollTop(){ return scrollEle.scrollTop; } function setScrollTop(value){ scrollEle.scrollTop = value; } //获取当前网页的展示高度(第一屏高度),此处Chrome正常 function getClientHeight(){ return clientEle.clientHeight; } })();