我试图用jQuery实现从上到下和从下到上的滚动条。我最近尝试百分比。 从顶部向底部,像素看起来OK。(意味着它)的底部到顶部仅作滚动没有完全结束,如果我提到的百分比为100在jquery中滚动到顶部并滚动到底部
$('#spnTop').on("click",function(){
var percentageToScroll = 100;
var percentage = percentageToScroll/100;
var height = jQuery(document).height();
var documentHeight = $(document).height();
var scroll = $(window).scrollTop();
alert(scroll);
var scrollAmount = Math.round((height) * percentageToScroll/ 100)-scroll;
//alert(point);
alert(scrollAmount);
$('html,body').animate({ scrollTop: scrollAmount }, 'slow', function() {
alert("reached top"); });
});
这里是fiddle。例如: 例如: percentageToScroll现在为100,但滚动的结束未完全结束。 (从下到上) 对于从上到下的是100,它会完全滚动到页面的底部。
我不知道如何使它可行。
谢谢。
玉萍
我不知道你想实现的东西。但您可以使用'scrollTop()' – james
您应该使用'console.log(...);'来进行调试,而不是'alert(...);'因为警报可能会破坏您的代码。 –