当元素在视口中时,jquery触发函数 [英] jquery trigger function when element is in viewport
本文介绍了当元素在视口中时,jquery触发函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在jquery.localscroll达到文档的某个点时触发事件。
I'd like to trigger an event when jquery.localscroll reaches a certain point of the document, a div.
可以说我们是从顶部div到第三。当它到达那里,然后动作schould触发。
Lets say we're scrolling vertically from the top div to the third. When it gets there, then the action schould trigger.
推荐答案
<!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>
这篇关于当元素在视口中时,jquery触发函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文