我想在 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/