So I have been looking around on SO and google for 20 minutes or so and cannot figure out if there is a jQuery function or a block of code somewhere that does this but what I am trying to due is run various jQuery functions as you scroll down the page. Is this possible, I was thinking there might be a way to use anchors to do this and just run a piece of code when you scroll to each anchor point? Thanks
问问题
2098 次
3 回答
0
尝试这个:
$(window).on("scroll", function() {
var scrollPosition = scrollY || pageYOffset;
if (scrollPosition > $("#someAnchor").position().top - $(window).height()) {
alert("run code here");
}
});
只要向下滚动到 ID 为“someAnchor”的元素,就会显示警报。这是您可以运行代码的地方。
于 2013-08-26T15:06:30.173 回答
0
于 2013-08-26T14:36:04.350 回答
0
用 jQuery 试试这个:
$(window).scroll(function () {
console.log("Hi");
});
于 2013-08-26T14:37:32.223 回答