作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不知道这是否容易,但我只是无法用 Waypoint.js 弄清楚一些东西当用户达到例如 100px 的滚动时,我需要向 #stickytop 添加一个类知道如何做到这一点吗?偏移对我不起作用。提前致谢
最佳答案
这并不是 jQuery 路径点的真正用例。它旨在测试特定元素距屏幕顶部的距离,而不是用户滚动的距离。
但是您可以使用 jQuery 轻松地完成您想要的操作:
$(document).on('scroll', function () {
// if the scroll distance is greater than 100px
if ($(window).scrollTop() > 100) {
// do something
$('#stickytop').addClass('myClass');
}
});
或者普通的 JavaScript:
document.addEventListener('scroll', function () {
if (window.scrollY > 100) {
var el = document.getElementById('#stickytop');
el.className = el.className + " myClass";
}
})
关于javascript - 航点.js : Add class when N distance to top,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26063187/
我是一名优秀的程序员,十分优秀!