我試圖用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(...);'因爲警報可能會破壞您的代碼。 –