jQuery视差导航不能滚动到目标
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;
});
这里的JSFIDDLE
相关文章:
- 幻灯片滚动javascript不起作用
- 将视口底部滚动到元素底部
- jQuery Lazy加载动画滚动
- 设置滑块分区上的滚动
- 结合jQuery和jetpack无限滚动
- 单击顶部导航时如何进行向下滚动效果(向下滑动).
- 滚动到容器中的下一个元素-几乎到了
- 只覆盖箭头键滚动事件
- Javascript如何找到滚动事件的来源
- 如何以多个目标可以同时处于活动状态的方式实现“滚动间谍”
- 当目标处于顶部滚动状态时,如何从菜单中激活项目
- 如何使滚动到目标平滑
- Javascript 锚点目标滚动到顶部不起作用
- 自动滚动到目标,iOS 中的 jQuery 运行得太远
- Javascript:如何增强鼠标滚动到目标部分
- JQuery渐入窗口滚动效果的目标元素的问题
- 滚动不透明度移动到和从目标元素
- jQuery视差导航不能滚动到目标
- 我可以用异步内容恢复正常的滚动到目标行为吗?
- 当链接和目标在不同的文档中时,使用JQuery平滑滚动