[英]jQuery- smooth scrolling a parallax page to certain anchors by mousewheel
我正在使用Stellar.js處理視差頁面,我像這樣將一些視差窗格彼此堆疊在一起:
當用戶向下滾動頁面並到達該窗格時,我希望每個窗格都能平滑滾動到頂部。 我的意思是我希望滾動器足夠聰明,以使每個窗格與屏幕頂部對齊。 我試過了但是沒用:
h = $(window).height();
t = $('#parallaxtop').offset().top + $('#parallaxtop').height();
if(t > h) {
$(window).scrollTop(t - h);
}
這是JSFiddle: http : //jsfiddle.net/LDaUw/
我發現這個工作:
var pageH = $(window).innerHeight(); //grab window height
$(window).scroll(function() {
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
var eTop = $('#parallaxtop').offset().top; //get the offset top of the element
var myOffset = eTop - $(window).scrollTop(); //determine the offset from window
if (myOffset > -100 && myOffset < pageH/2) { //if the offset is less than the half of page scroll to the panel
$('#parallaxtop').ScrollTo({ //ScrollTo JQuery plugin
});
}
}, 250)); //this will be calculated 250ms after finishing every scroll
});
我已經使用ScrollTo JQuery插件進行平滑滾動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.