javascript - 有人可以向我解释如何设置滚动功能可以向下/向上滚动以使用 jquery 的像素数量吗?

标签 javascript jquery css scroll transform

$(window).scroll(function(){
// scroll 100vh down on first scroll

// scroll another 100vh down on second scroll
})

我见过一个插件可以做到这一点,但我希望能够理解其逻辑是如何工作的。有人可以向我解释一下,或者至少让我指向一个可以进一步解释它的网站吗?

最佳答案

$(window).scroll(function(){ //Function called when window is scrolled.

})

JQuery Scroll

The scroll event is sent to an element when the user scrolls to a different place in the element. It applies to window objects, but also to scrollable frames and elements with the overflow CSS property set to scroll (or auto when the element's explicit height or width is less than the height or width of its contents).

当 div 的宽度/高度超过设备的可用宽度/高度时,浏览器将为您提供滚动条以向下滚动并查看溢出的元素。

Jquery scroll 允许您在用户在提供的选择器内滚动时监听事件。

它将调用您作为参数传递给 jquery 滚动函数的处理程序(函数)。

此外,您不需要手动滚动容器。浏览器会自动滚动溢出容器的内容,但您可能希望增加滚动条的滚动步数。

如何增加步数?

通常,当您滚动时,可滚动容器的 scrollTop 属性会以固定步长 (1-10px) 发生变化。

scrollTop 属性决定有多少内容从可滚动容器的顶部溢出,并从容器底部显示更多像素,就像视口(viewport)一样。

因此,您可以向 scrollTop 添加更多像素,并比默认滚动更多。

检查这个 answer我的

关于javascript - 有人可以向我解释如何设置滚动功能可以向下/向上滚动以使用 jquery 的像素数量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44435551/

相关文章:

javascript - jQuery next().addClass() 和 prev().addClass() 问题

html - 当 CSS 属性更改时,主体未调整

javascript - 更改 IE 中脚本标签的innerHTML以显式加载google plusone按钮

css - 如何将多个css文件和javascript文件编译成一个文件?

html - Div 消失在页脚后面

javascript - 通过弹出窗口在父窗口中填充选择框

javascript - 一旦用户鼠标离开文本字段就运行函数

javascript - 如何在从 react 列表中呈现的已删除行上运行加载程序图标?

javascript - 单选按钮隐藏/显示所有内容

javascript - 使 Div 区域适应背景图像大小