Javascript 使用onepage\u scroll插件时获取JQuery中的滚动位置
我正在使用伟大的网站。低于设定的阈值,页面将恢复为正常滚动行为。然而,在这一点上,当我尝试使用scrollTop()获取距页面顶部的距离时,它总是返回0Javascript 使用onepage\u scroll插件时获取JQuery中的滚动位置,javascript,jquery,scrolltop,Javascript,Jquery,Scrolltop,我正在使用伟大的网站。低于设定的阈值,页面将恢复为正常滚动行为。然而,在这一点上,当我尝试使用scrollTop()获取距页面顶部的距离时,它总是返回0 var vph = $(window).height(); var responsiveThreshold = 640; $(".onepage_scroll").onepage_scroll({ sectionContainer: "section", // sectionContainer accepts any kind
var vph = $(window).height();
var responsiveThreshold = 640;
$(".onepage_scroll").onepage_scroll({
sectionContainer: "section", // sectionContainer accepts any kind of selector in case you don't want to use section
easing: "ease", // Easing options accepts the CSS3 easing animation such "ease", "linear", "ease-in",
// "ease-out", "ease-in-out", or even cubic bezier value such as "cubic-bezier(0.175, 0.885, 0.420, 1.310)"
animationTime: 1000, // AnimationTime let you define how long each section takes to animate
pagination: false, // You can either show or hide the pagination. Toggle true for show, false for hide.
updateURL: true, // Toggle this true if you want the URL to be updated automatically when the user scroll to each page.
beforeMove: scrollCatchBefore, // This option accepts a callback function. The function will be called before the page moves.
afterMove: scrollCatchAfter, // This option accepts a callback function. The function will be called after the page moves.
loop: false, // You can have the page loop back to the top/bottom when the user navigates at up/down on the first/last page.
keyboard: true, // You can activate the keyboard controls
responsiveFallback: responsiveThreshold // You can fallback to normal page scroll by defining the width of the browser in which
// you want the responsive fallback to be triggered. For example, set this to 600 and whenever
// the browser's width is less than 600, the fallback will kick in.
});
// Fix menu if page is too small
if(vpw<responsiveThreshold) {
$("#navigation").hide();
/* Every time the window is scrolled ... */
$('body').scroll( function(){
var scrollPos = $('html').scrollTop();
console.log(vph);
console.log(scrollPos);
if(scrollPos > vph) {
$("#navigation").fadeIn();
} else {
$("#navigation").fadeOut();
}
});
}
看看onepage_scroll的工作原理,它并没有以典型的方式移动主体或div。所以scrollTop不是这里的解决方案 它正在使用translate3d处理下面讨论的div
<div class="main onepage-wrapper">
这个答案可能对你有用。。。
要了解区段的当前索引:
var nCurSect = $("section.active", ".main").data("index");
然后,您可以将其乘以屏幕高度并获得偏移量。低于responsiveFallback宽度,但正常滚动保持正确?当您设置
responsiveFallback
的值时,插件会对$(窗口)作出反应。调整调用内部responsive()
函数的事件大小。如果$(window).width()
小于responsiveFallback
值,插件会将class禁用的一页滚动条添加到正文
标记中。如果大于该值,则该类将被删除。但这不会说明低于该点的responsiveFallback宽度滚动应恢复正常。
-webkit-transform: translate3d(0px, -100%, 0px);
var nCurSect = $("section.active", ".main").data("index");