当元素位于视口(viewport)中时jquery触发函数

标签 jquery function triggers viewport

我想在 jquery.localscroll 到达文档的某个点(div)时触发一个事件。

假设我们从顶部 div 垂直滚动到第三个 div。当它到达那里时,就会触发该操作。

最佳答案

jQuery Waypoints 插件 http://imakewebthings.github.com/jquery-waypoints/应该可以解决问题

更新

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery Waypoints Plugin - Test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
    <script src="http://imakewebthings.github.com/jquery-waypoints/waypoints.min.js" type="text/javascript"></script>
    <style type="text/css">
        #mydiv {background-color:#FF0000; margin:1500px 0;}
    </style>
</head>
<body>

<div id="mydiv">
    Content goes here
</div>

<script type="text/javascript">
$(function() {
       $('#mydiv').waypoint(function() {
         window.location.href = 'http://google.com';
         }, {
           offset: '100%'
         });
    });
</script>
</body>
</html>

关于当元素位于视口(viewport)中时jquery触发函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5911138/

相关文章:

jquery 无法识别 fullcalendar

jquery - div contenteditable ="true"

javascript - JS中私有(private)方法的一种尝试

MySQL如果不存在则创建触发器?

postgresql - Postgres 中的 AFTER 触发器会阻止插入/更新吗?

javascript - 在正则表达式匹配上调用函数

c - 在 C 中传递结构的一部分

python - 默认参数替代无?

jquery - 如何用 jQuery 触发输入事件?

javascript - jQuery 按钮不执行?