我正试着在我的网站www.dirtycookie.co上的instagram上添加prettyPhoto到我的照片中
我可以成功地从instagram API中拉出图片,但是我不能将prettyPhoto功能添加到提要中的图片。下面是我使用prettyPhoto钩子进行的ajax调用:
<script>
$(function() {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "https://api.instagram.com/v1/users/<?=$user_id?>/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf",
success: function(data) {
for (var i = 0; i < <?=$num_to_display?>; i++) {
jQuery('.instagram').append('<div class="instagram-placeholder"><a href="' + data.data[i].images.standard_resolution.url + '" rel="prettyPhoto"><img alt="'+ data.data[i].caption.text +'" class="instagram-image" src="' + data.data[i].images.thumbnail.url +'"/></a></div>');
}
}
});
});
</script>它的行为几乎就像没有调用jquery.prettyPhoto.js一样,我已经确认它在/js/文件夹中。
下面是我的init脚本和正文的底部:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>使用Firebug,我可以看到Ajax正确地放入了rel="prettyPhoto“中。
有人有什么建议吗?
谢谢,克里斯
发布于 2013-02-12 11:57:02
您在'domready‘处的锚点上附加了prettyPhoto()函数,甚至在内容从AJAX调用中拉入之前也是如此。因此它不起作用。尝尝这个。
$(function() {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "https://api.instagram.com/v1/users/<?=$user_id?>/media/recent/?access_token=13137.f59def8.1a759775695548999504c219ce7b2ecf",
success: function(data) {
for (var i = 0; i < <?=$num_to_display?>; i++) {
jQuery('.instagram').append('<div class="instagram-placeholder"><a href="' + data.data[i].images.standard_resolution.url + '" rel="prettyPhoto"><img alt="'+ data.data[i].caption.text +'" class="instagram-image" src="' + data.data[i].images.thumbnail.url +'"/></a></div>');
}
$("a[rel^='prettyPhoto']").prettyPhoto();
}
});
});https://stackoverflow.com/questions/14824696
复制相似问题