[英]how to make page scroll more smooth with Waypoints animations?
我的頁面上有幾節內容,其中包含Waypoints CSS3動畫。 您可以通過單擊菜單鏈接或向下滾動來到達這些部分,在兩種情況下我都希望Waypoint觸發。
關鍵是要有以下幾個部分:關於,服務,價格,圖庫,團隊等,假設單擊圖庫,我不希望前面的部分觸發,因為頁面根本無法平滑滾動。
到目前為止,我設法編寫了此代碼(其他部分依次類推):
var prices = new Waypoint({
element: document.getElementById('prices'),
handler: function(direction) {
// animations in the section
},
offset: 410
});
以此類推。 然后,如果所單擊的菜單項不在后面,則在前面的部分中禁用Waypoints:
$('.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;
});
它的工作原理肯定比以前更平滑,但仍然不如我希望的那樣平滑(而且我在其他網站上看到了它的效果)。
如何使它更有效?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.