我发现这个工作:
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 插件进行平滑滚动。