Team:USTC CHINA/xyshao/fucmenu1.js
From 2013.igem.org
(Difference between revisions)
(One intermediate revision not shown) | |||
Line 8: | Line 8: | ||
//滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定 | //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定 | ||
if(scroH>=navH){ | if(scroH>=navH){ | ||
- | $(".nav").css({"position":"fixed","top":0 | + | $(".nav").css({"position":"fixed","top":0}); |
}else if(scroH<navH){ | }else if(scroH<navH){ | ||
$(".nav").css({"position":"static","margin":"0 auto"}); | $(".nav").css({"position":"static","margin":"0 auto"}); |
Latest revision as of 11:11, 8 August 2013
$(function(){ //获取要定位元素距离浏览器顶部的距离 var navH = $(".nav").offset().top; //滚动条事件 $(window).scroll(function(){ //获取滚动条的滑动距离 var scroH = $(this).scrollTop(); //滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定 if(scroH>=navH){ $(".nav").css({"position":"fixed","top":0}); }else if(scroH<navH){ $(".nav").css({"position":"static","margin":"0 auto"}); } console.log(scroH==navH); }) })// JavaScript Document