我在 jquery
中滚动到顶部和滚动到底部。在那里我按照百分比滚动。例如:
如果从上到下的滚动是 50%
那么它从上到下的滚动是 50%
它已经作品。但是现在我想滚动 50%,如果我再次单击然后它将剩余的 50% 滚动到页面底部。我不确定如何在 jquery 中执行此操作。
这是 fiddle 任何建议都很好。 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/