在近视口中触发点击
Trigger Click when in Near Viewport
我在页脚有一个 "Load More" 按钮。
现在,当我滚动 body
并且 刚好在 #loadSomeMoreCrap
上方时,我想触发 runthisfunction();
.
谁能帮我解决这个问题。我浏览了 JScroll,但没有找到答案。任何帮助都将非常感谢。
HTML
<div id="PasteCrapHere"></div>
<button id="loadSomeMoreCrap">Load More</button>
jQuery
$('#loadSomeMoreCrap').click(function(){
runthisfunction();
});
function runthisfunction(){
//something done here! none your'e business
}
粗略,但您可以添加任何您想要的内容:
$(document).scroll(function() {
var b = $('#btn1').offset().top;
var s = $(document).scrollTop() + $(window).height();
if (s > b)
YourFunctionCallHere();
});
function YourFunctionCallHere() {
/* Fill container until it no longer fits on screen */
while ($(document).scrollTop() + $(window).height() > $('#btn1').offset().top *.8) {
$('#container').append(count + '<br>');
count = count + 1;
}
}
/* Initialize container with data */
window.count = 1;
$(function() {
YourFunctionCallHere();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container"></div>
<button id="btn1">click me</button>
我在页脚有一个 "Load More" 按钮。
现在,当我滚动 body
并且 刚好在 #loadSomeMoreCrap
上方时,我想触发 runthisfunction();
.
谁能帮我解决这个问题。我浏览了 JScroll,但没有找到答案。任何帮助都将非常感谢。
HTML
<div id="PasteCrapHere"></div>
<button id="loadSomeMoreCrap">Load More</button>
jQuery
$('#loadSomeMoreCrap').click(function(){
runthisfunction();
});
function runthisfunction(){
//something done here! none your'e business
}
粗略,但您可以添加任何您想要的内容:
$(document).scroll(function() {
var b = $('#btn1').offset().top;
var s = $(document).scrollTop() + $(window).height();
if (s > b)
YourFunctionCallHere();
});
function YourFunctionCallHere() {
/* Fill container until it no longer fits on screen */
while ($(document).scrollTop() + $(window).height() > $('#btn1').offset().top *.8) {
$('#container').append(count + '<br>');
count = count + 1;
}
}
/* Initialize container with data */
window.count = 1;
$(function() {
YourFunctionCallHere();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container"></div>
<button id="btn1">click me</button>