【发布时间】:2014-02-19 19:15:40
【问题描述】:
有些东西是未定义的,它对我不起作用。我想我做错了什么,但我不知道是什么。
//change the window hash
var changeHash = function(a) {
document.location.hash = a
};
//get the scrollPos
var scrollPos = function(){
$(window).scrollTop()
};
//find the position of the top of element
var topPos = function(a){
$(a).offset().top
};
//find the position of the bottom of element
var bottomPos = function(a){
$(a).offset().top + $(a).height()
};
$(window).scroll(function() {
if ($(this).scrollTop() < bottomPos('#top')) {
$('.navbar').fadeOut('fast');
changeHash('');
}
else {
$('.navbar').fadeIn('fast');
return;
if(scrollPos <= topPos('#services') && scrollPos >= bottomPos('#services')){
changeHash('services');
}
if(scrollPos <= topPos('#work') && scrollPos >= bottomPos('#work')){
changeHash('work');
}
if(scrollPos <= topPos('#connect') && scrollPos >= bottomPos('#connect')){
changeHash('connect');
}
}
});
【问题讨论】:
标签: jquery scroll scrolltop hashchange