[英]How to lazy-load images from Instagram on page scroll?
I am trying to figure out how to do an endless scroll sort of effect when calling an API with ajax. 我试图弄清楚如何用ajax调用API时产生无限滚动效果。
Right now, it only grabs the first 20. I need it grab the first 14, and then once the user gets to the bottom of the div, it get's another 14 (if there are 14 more to get). 现在,它只获取前20个。我需要它获取前14个,然后一旦用户到达div的底部,它就会再获取14个(如果还有14个)。
Does anyone know how I can do this? 有人知道我该怎么做吗? Or at least the best way to show 14 more and so on once the user starts scrolling? 还是至少在用户开始滚动后再显示14个这样的最佳方式?
MAIN PAGE 主页
<a id="popup" href="https://api.instagram.com/oauth/authorize/?client_id=CLIENT_ID&redirect_uri=http://localhost/instagramAjax.php&response_type=token">
<img src="/images/instagram-login-button.png" />
</a>
<div style="padding:5px;width:340px;border:1px solid black;height:400px;overflow-y:scroll;">
<ul id="photo-list"></ul>
</div>
instagramAjax.php instagramAjax.php
var token = window.location.href;
token = token.split("#access_token=");
window.opener.instagram(token[1]);
window.close();
javascript JavaScript的
$(document).ready(function() {
$("#popup").click(function(e) {
var url = $(this).attr('href');
e.preventDefault();
window.open(url, 'authWindow', "width=800,height=436");
});
function instagram(value)
{
var token = value;
$.ajax({
type: "GET",
dataType: "jsonp",
url: "https://api.instagram.com/v1/users/self/media/recent?access_token="+token+"",
success: function(e)
{
for (index in e.data) {
$('ul#photo-list').append("<li><img src="+e.data[index].images.standard_resolution.url+" /></li>");
}
}
});
}
});
I answered my own question. 我回答了我自己的问题。 Just have to grab the next_url data from the api and then call it when it reaches to the bottom of the div. 只需从api中获取next_url数据,然后在到达div底部时调用它即可。 Here is what I did to find out if the user is at the bottom of the div. 这是我做的事情,以确定用户是否位于div的底部。
$('#container').bind('scroll', function()
{
if($(this).scrollTop() + $(this).innerHeight()>=$(this)[0].scrollHeight) { }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.