Jquery 滚动通过标题时显示导航div时出现故障
这是我已经得到的代码:Jquery 滚动通过标题时显示导航div时出现故障,jquery,scroll,Jquery,Scroll,这是我已经得到的代码: $(document).ready(function() { /*Scrolls to whichever element is clicked if is has .scrollPage class */ $('.scrollPage').click(function() { var elementClicked = $(this).attr("href"); var destination = $(elementClic
$(document).ready(function()
{
/*Scrolls to whichever element is clicked if is has .scrollPage class */
$('.scrollPage').click(function() {
var elementClicked = $(this).attr("href");
var destination = $(elementClicked).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-0}, 500 );
return false;
});
$('#backToTop').hide();
$('#sideNav').hide();
var headerHeight = $('#header').height();
/* Detect when page is scrolled */
$(document).scroll(function(){
var scrolledpx = parseInt($(document).scrollTop());
if (scrolledpx > headerHeight) {
$("#backToTop").fadeIn(500);
$("#sideNav").fadeIn(500);
}
else if (scrolledpx < headerHeight) {
$("#backToTop").fadeOut(500);
$("#sideNav").fadeOut(500);
}
});
});
问题是,当我在标题下方滚动时,“backToTop”不会显示,但当我单击链接滚动到某个特定部分(效果很好)时,它似乎为“backToTop”留下了一个空间(即,它只是将页面向下移动一行),但不会显示。我做错了什么?对不起,很简单。我在CSS中使用了.backToTop,而不是#backToTop。看到这个小提琴了吗: 您的css应该是:
#backToTop {
position: fixed;
top: 10px;
left: 10px;
}
因为backToTop
是分配给div的id
(不是类
)
.backToTop {
position: fixed;
top: 10px;
left: 10px;
}
#backToTop {
position: fixed;
top: 10px;
left: 10px;
}