[英]jQuery parallax navigation doesn't scroll to target
我已经组装了一个视差滚动演示,但我在导入内容之间遇到问题。
Header
和Footer
是固定的,其余的都没有。
在变量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;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.