You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.0 KiB
32 lines
1.0 KiB
$(function(){
|
|
$('#return-top').hide();
|
|
$(function(){
|
|
$(window).scroll(function(){
|
|
if($(window).scrollTop()>10){
|
|
$('#return-top').fadeIn(300);
|
|
}else{
|
|
$('#return-top').fadeOut(200);
|
|
}
|
|
});
|
|
$('#return-top').click(function(){
|
|
$('body,html').animate({scrollTop:0},300);
|
|
return false;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//获取要定位元素距离浏览器顶部的距离
|
|
var navH = $(".nav").offset().top;
|
|
//滚动条事件
|
|
$(window).scroll(function(){
|
|
//获取滚动条的滑动距离
|
|
var scroH = $(this).scrollTop();
|
|
//滚动条的滑动距离大于等于定位元素距离浏览器顶部的距离,就固定,反之就不固定
|
|
if(scroH>=navH){
|
|
$(".nav").css({"position":"fixed","top":0,"left":"0","margin-left":"0","right": 0,"z-index": 99999});
|
|
}else if(scroH<navH){
|
|
$(".nav").css({"position":"static","margin":"0 auto"});
|
|
}
|
|
})
|
|
})
|