【问题标题】:scroll down to document height but + 100向下滚动到文档高度但 + 100
【发布时间】:2020-09-16 16:31:17
【问题描述】:

我得到了这个脚本

$("body, html").animate({scrollTop: $(document).height()}, 1000)

如上所示,它将使页面向下滚动到文档高度:也就是底部。 但是在我的情况下它太低了,我想向下滚动到bottom:100px;bottom:10%; 这可能吗?我找到了examples,但they 对我不起作用。 我缺少什么让它工作?:)

【问题讨论】:

  • 嗨,杰克。所以如果你尝试scrollTop: $(document).height() - 100 它不起作用?

标签: javascript jquery


【解决方案1】:

当然,您可以将 scrollTop 的值设置为您可以数学计算的任何值:

// Top is 100 px short of bottom
$("body, html").animate({scrollTop: $(document).height() - 100}, 1000)
// 90% scroll down
$("body, html").animate({scrollTop: $(document).height() * 0.9}, 1000)

请注意,对于所有这些,100 像素非常小。您的浏览器窗口必须小于 100 像素高,才能滚动到底部。

您也可以在方程式中使用浏览器窗口的可见高度:

$(window).height()

【讨论】:

  • 感谢您的解释,因为我已经向下滚动了一点 - 100px 的高度总是滚动到底部,但现在我明白了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-14
  • 2016-03-21
  • 2013-05-03
  • 1970-01-01
  • 2012-02-16
  • 1970-01-01
相关资源
最近更新 更多