Skip to content

Instantly share code, notes, and snippets.

@brianyang
Last active October 14, 2019 23:21
Show Gist options
  • Save brianyang/5000777 to your computer and use it in GitHub Desktop.
Save brianyang/5000777 to your computer and use it in GitHub Desktop.
jQuery plugin
(function($){
// $(this).empty().append('load images here')
$.fn.flickrPhotos = function(){
var that = this
, next = '<button id=next>next</button>'
, prev = '<button id=prev>prev</button>'
$('body').append(next).append(prev)
$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?&limit=50', {
format:'json'
}, function(d){
$(d.items).each(function(i){
var imgurl = d.items[i].media.m.replace('_m','')
var img = '<img class=flickr src=' + imgurl + ' >'
$(that).append(img)
})
$('.flickr').eq(0).addClass('first')
$('.flickr').hide()
$('.first').show()
})
}
var events = function(){
console.log ('inner event')
$('body').on('click','#next', function(){
var visibleImg = $('.flickr:visible')
, nextImg = $(visibleImg).next()
$(visibleImg).hide()
$(nextImg).show()
console.log(visibleImg)
})
}
events()
}(jQuery))
// $('body').flickrPhotos()
/*
USAGE:
$(element).flickrPhotos()
will load flickr photos in 'element'
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment