我在jquery
中将滚动到顶部,然后滚动到底部。在那我做滚动百分比。例如:
如果从上到下的滚动是50%
,则它以50%
从上到下滚动已经起作用。但是现在我想滚动50%(如果再次单击),然后将剩余的50%滚动到页面底部。我不确定如何在jquery中执行此操作。
这是小提琴。任何建议都很好。
http://jsfiddle.net/TkYpY/
谢谢,
维基
最佳答案
$('#spnTop').on("click", function () {
var percentageToScroll = 50;
var percentage = percentageToScroll / 100;
var height = $(document).height() - $(window).height();
if(scrollAmount > 0 )
{
scrollAmount = scrollAmount - (height * percentage);
}
console.log('scrollAmount: ' + scrollAmount);
$('html,body').animate({
scrollTop: scrollAmount
}, 'slow', function () {
console.log("reached top");
});
});
var scrollAmount = 0;
$('#spnbottom').on("click", function () {
var percentageToScroll = 50;
var percentage = percentageToScroll / 100;
var height = $(document).height() - $(window).height();
if( scrollAmount < height)
{
scrollAmount = scrollAmount + height * percentage;
}
console.log('scrollAmount: ' + scrollAmount);
jQuery("html, body").animate({
scrollTop: scrollAmount
}, 900);
});
关于javascript - 滚动顶部jQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19585858/