Created
January 11, 2014 03:30
-
-
Save markyun/8366618 to your computer and use it in GitHub Desktop.
Jquery获取Flickr的图片 jQuery-Flickr-Photo-Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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