我已经制作了一个视差滚动演示,但在内容之间导航时遇到问题。
页眉
和页脚
已修复,其余部分则未修复。关于变量
section3Top
section4Top
我猜高度计算不正确。
我看不到问题。
请看看我的演示并尝试单击菜单。它应该通过单击菜单、滚动和调整大小来工作。
演示:http://fiddle.jshell.net/Zza7t/
JS:
function redrawDotNav(){
var section1Top = 0;
var section2Top = $('#BuyKeep').offset().top - (($('#Rentals').offset().top - $('#BuyKeep').offset().top) / 2);
var section3Top = $('#Rentals').offset().top - (($('#WaystoWatch').offset().top - $('#Rentals').offset().top) / 2);
var section4Top = $('#WaystoWatch').offset().top - (($(document).height() - $('#WaystoWatch').offset().top) / 2);
$('nav#primary a').removeClass('active');
if($(document).scrollTop() >= section1Top && $(document).scrollTop() < section2Top){
$('nav#primary a.about').addClass('active');
} else if ($(document).scrollTop() >= section2Top && $(document).scrollTop() < section3Top){
$('nav#primary a.BuyKeep').addClass('active');
} else if ($(document).scrollTop() >= section3Top && $(document).scrollTop() < section4Top){
$('nav#primary a.Rentals').addClass('active');
} else if ($(document).scrollTop() >= section4Top){
$('nav#primary a.WaystoWatch').addClass('active');
}
}
function scrollFooter(scrollY, heightFooter) {
if(scrollY >= heightFooter) {
$('#WaystoWatch').css({
'bottom' : '0px'
});
}
else {
$('#WaystoWatch').css({
'bottom' : '-' + heightFooter + 'px'
});
}
}
function heightsCalculator(){
var windowHeight = $(window).height(),
footerHeight = $('#WaystoWatch').height(),
heightDocument = (windowHeight) + ($('#BuyKeep').height()) + ($('#Rentals').height()) + ($('#WaystoWatch').height()) - 0;
$('#scroll-animate, #scroll-animate-main').css({
'height' : heightDocument + 'px'
});
$('#about').css({
'height' : windowHeight + 'px'
});
$('.wrapper-parallax').css({
'margin-top' : windowHeight + 'px'
});
scrollFooter(window.scrollY, footerHeight);
window.onscroll = function(){
var scroll = window.scrollY;
$('#scroll-animate-main').css({
'top' : '-' + scroll + 'px'
});
$('#about').css({
'background-position-y' : 50 - (scroll * 100 / heightDocument) + '%'
});
scrollFooter(scroll, footerHeight);
}
}
最佳答案
唯一对我不起作用的链接是“页脚”。因为你已经固定了它的位置,所以当你上下滚动页面时,它的偏移量将会改变。您想要对标题执行相同的操作,并滚动页面的特定位置,在本例中为底部。还有一些东西会重新调整您的“页脚”高度,我无法找到您在哪里这样做或为什么这样做,但我认为这是没有必要的。
$('a.WaystoWatch').click(function(){
$('html, body').animate({
scrollTop:$('body').height()
}, 1000, function() {
parallaxScroll();
});
return false;
});
关于javascript - jQuery 视差导航不会滚动到目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24657350/