当用户滚动到特定的div时运行javascript函数 [英] Run javascript function when user scrolls to a specific div

查看:82
本文介绍了当用户滚动到特定的div时运行javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次用户滚动到另一个div或页面的另一部分时,我都希望运行不同的功能.反正我能做到吗?

I have a different function I want to run each time a user scrolls to another div or to another section of the page. Is there anyway I can do that?

推荐答案

全部在这里回答->>

Allready Answered here -->> Dynamic Scroll Position in Jquery

有一个很棒的插件可以做到这一点,叫做 WAYPOINT

There is a great plugin to do this called WAYPOINT

我已在 jsfiddle检出示例

I have setup an example on jsfiddle check it out

HTML

<div class="first"></div>
<div class="second"></div>

CSS

.first {
    background:green;
    height: 600px;
    width:100%;
}
.second {
    background:red;
    height: 600px;
    width:100%;
}

JS

$('.second').waypoint(function() {
    alert('You have scrolled to an entry.');
}, {
    offset: '100%'
});

这篇关于当用户滚动到特定的div时运行javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆