作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 jQuery,如何将 div 滚动 N 个像素?
到目前为止我已经尝试过了
$("div.foo").scrollTop(75); //scroll down by 75 pixels
最佳答案
来自scrollTop 的 jQuery 文档:
Description: Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.
您调用的函数版本设置滚动条的垂直位置从元素顶部开始,而不是从当前位置开始。因此,为了从当前位置向下滚动,您首先必须检索当前位置。有几种方法可以做到这一点,但你可以这样做:
var $foo = $("div.foo");
$foo.scrollTop($foo.scrollTop() + 75); // scroll 75px down from current
关于javascript - jquery:如何将div滚动n个像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43922640/
我是一名优秀的程序员,十分优秀!