【发布时间】:2016-07-14 10:21:15
【问题描述】:
我的页面上有几个部分,上面有 Waypoints css3 动画。您可以通过单击菜单链接或向下滚动来访问这些部分,我希望 Waypoints 在这两种情况下都会触发。
问题是有部分:关于、服务、价格、图库、团队等,假设单击图库,我不希望前面的部分触发,因为页面根本不能平滑滚动。
到目前为止,我设法写了这个(其他部分等等):
var prices = new Waypoint({
element: document.getElementById('prices'),
handler: function(direction) {
// animations in the section
},
offset: 410
});
其他部分以此类推。然后,如果单击的菜单项更远,我会在前面的部分禁用航点:
$('.link').click(function(){
var nameOfLink = $(this).attr('href').replace('#', '');
if(nameOfLink == 'prices') {
Waypoint.disableAll();
navbar.enable();
prices.enable();
}
if(nameOfLink == 'gallery') {
Waypoint.disableAll();
navbar.enable();
gallery.enable();
}
if(nameOfLink == 'team') {
Waypoint.disableAll();
navbar.enable();
team.enable();
}
这是平滑滚动代码:
$('html, body').animate({
scrollTop: $( $(this).attr('href') ).offset().top -104
}, 1000);
return false;
});
它可以工作,肯定比以前更流畅,但仍然没有我想要的那么流畅(我在其他网站上看到它也能正常工作)。
我怎样才能使它更有效?
【问题讨论】:
标签: javascript jquery jquery-waypoints