Skip to content

Instantly share code, notes, and snippets.

@markyun
Created January 11, 2014 03:30
Show Gist options
  • Save markyun/8366618 to your computer and use it in GitHub Desktop.
Save markyun/8366618 to your computer and use it in GitHub Desktop.
Jquery获取Flickr的图片 jQuery-Flickr-Photo-Plugin
(function($){
$.fn.flickrPhoto = function(options){
var settings = $.extend({
url : 'http://www.flickr.com/photos/markyun/11532861994/',
key : 'a66ae3b787a9d02a3da0f2b63ac621be',
secret : '89f35a97fe9d0df6'
}, options),
id,
method = 'flickr.photos.getInfo',
format = 'json',
collection = this;
id = settings.url.match(/\/photos\/(.*)/)[1].split('/')[1];
$.ajax({
url: 'http://www.flickr.com/services/rest/?method='+method+'&format='+format+'&api_key='+settings.key,
dataType: 'jsonp',
data: {'photo_id':id},
type: 'GET',
jsonpCallback: 'jsonFlickrApi',
success: function(data){
collection.each(function(){
$(this).append('<img src="http://farm'+data.photo.farm+'.static.flickr.com/'+data.photo.server+'/'+id+'_'+data.photo.secret+'.jpg">');
});
}
});
return collection;
};
})(jQuery);
$('body').flickrPhoto();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment