javascript - Trigger Click when in Near Viewport -
i have "load more" button @ footer.
now when scroll body , just above #loadsomemorecrap want trigger runthisfunction();.
can me figure out. went through jscroll didnt find answer. great thanks.
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 }
crude, can add whatever else want:
$(document).scroll(function() { var b = $('#btn1').offset().top; var s = $(document).scrolltop() + $(window).height(); if (s > b) yourfunctioncallhere(); }); function yourfunctioncallhere() { /* fill container until no longer fits on screen */ while ($(document).scrolltop() + $(window).height() > $('#btn1').offset().top *.8) { $('#container').append(count + '<br>'); count = count + 1; } } /* initialize container 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>
Comments
Post a Comment