Making a Flickr-powered Slideshow

Demo Download

Today we will be developing a jQuery plugin that will make it easy to create slideshows, product guides or presentations from your Flickr photo sets. The plugin will be using Flickr's APIs and YQL to fetch the photos in the sets, after which it will create the markup of the slideshow and listen for events.

Updated on Oct 11th 2011: Due to a change in Flickr's API, you are now required to provide an API key when requesting the photos in a set. The script and this tutorial were updated to reflect this change. If you have downloaded this script before, replace jqFlick.js and script.js. You will also need to generate a Flickr API key (as explained in the tutorial) and paste it in script.js.


Before starting with jqFlick (the name of our plugin), lest first lay down the HTML structure of the underlying document. I am including the plugin's CSS stylesheet - jqFlick.css, which we will be creating in the next step, and the plugin's js file - jqFlick.js.


<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jqFlick - Flickr Micro Slider Plugin | Tutorialzine Demo</title>

<link rel="stylesheet" type="text/css" href="assets/css/styles.css" />
<link rel="stylesheet" type="text/css" href="assets/jqFlick/jqFlick.css" />


<div id="page">

    <h1>Flickr Powered Micro Slider</h1>

    <div id="flickrSlider"></div>

    <p class="demos">More demos: <select>
        <option value="1" selected>Presentation Example</option>
        <option value="2">Photo Slideshow</option>
        <option value="3">Product Shots (small)</option>


<script src=""></script>
<script src="assets/jqFlick/jqFlick.js"></script>
<script src="assets/js/script.js"></script>


Additionally, we have styles.css, which styles the page itself, and script.js, which calls the plugin. Also, we have a select element with demos of three different configurations of the plugin. We will come back to this in a moment.

The other important element in the fragment above is the #flickrSlider div, which is going to be populated with the slider's HTML by the jqFlick plugin:

Generated Code

<div id="flickrSlider" class="flickrSliderHolder" style="width: 500px; height: 345px;">
    <span class="caption"></span>
    <ul style="width: 1000px; height: 320px; left: 0px;">
        <li style="background-image: url('example.jpg'); width: 500px;"></li>
        <li style="background-image: url('example2.jpg'); width: 500px;"></li>
    <div class="arrows">
        <a class="previous" href="#"></a>
        <a class="next" href="#"></a>

The #flickrSlider div is assigned a class name - .flickrSliderHolder, a width and a height. Inside it we have an unordered list with the slides, an arrow div holder with previous and next arrows, and a span for the captions. The unordered list is set to be wide enough to accommodate the LIs side by side. The slide animation is achieved by animating the left property of the UL.



We need to provide the plugin with its own stylesheet, so it is easier to include into a website. This stylesheet must only affect the markup generated by the plugin, and we have to make sure it does not corrupt any other elements on the page. To achieve this, we are going to prefix the styles with the .flickrSliderHolder class name, assigned to the slideshow holder by the plugin.



.flickrSliderHolder ul{

.flickrSliderHolder ul li{
    background-position:center center;

.flickrSliderHolder .arrows{

.flickrSliderHolder .arrows a{
    background:url('arrows.png') no-repeat top left;

.flickrSliderHolder a.previous:hover{
    background-position:left bottom;

    background-position:top right;

    background-position:bottom right;

.flickrSliderHolder .caption{
    line-height: 22px;

Once called, jqFlick assigns the .flickrSliderHolder class to the slider holder div, and generates the markup that we saw in the previous step. The code above styles the arrows, caption, unordered list and the container.


The jQuery Code

Starting with the jQuery section, lets first see what a response from the Flickr API looks like:

Sample YQL Response

    "query": {
        "count": 3,
        "created": "2011-02-19T20:11:18Z",
        "lang": "en-US",
        "results": {
            "photo": [{
                "farm": "6",
                "id": "5456788328",
                "isprimary": "1",
                "secret": "e9eddccf8e",
                "server": "5213",
                "title": "The title of the image becomes an optional caption."
            }, {
                "farm": "6",
                "id": "5456179165",
                "isprimary": "0",
                "secret": "28bae85307",
                "server": "5216",
                "title": "There are no limits really."
            }, {
                "farm": "6",
                "id": "5456179233",
                "isprimary": "0",
                "secret": "e05287691f",
                "server": "5018",
                "title": "What more do you need.."

Here I've selected the photos that are contained in this photoset. The response contains useful information about the images. We are going to use the farm, id, secret, and server properties of these objects to put together the URL at which the photos are located, while the title properties are going to be used as captions.

You can find your photos at the following address, by replacing the keywords with the objects' values:


In our plugin, we will be using Flickr's API method for listing photos in a photoset. However, to communicate with Flickr's APIs, we will need to register for an API key.

API key registration

This step is actually quite simple. You need to have a valid Flickr registration and visit this page. After you choose the type of the registration (non commercial in our case), you fill in the application details. You now get your API key, which you will need in a second.

For more info on the various Flickr APIs you can go to their documentation page. If you would like to know more about the URL addresses of their photos (including info on how to fetch different image sizes) see here. You can also read more about YQL in our previous YQL tutorials.

Now we are ready to write the jQuery code. As you know, encapsulating jQuery functionality in a plugin has many benefits, as you can read from our jQuery plugin tutorial. Lets see what jqFlick.js, the main plugin file, looks like:



    $.fn.jqFlick = function(options){

        // Default options:

        options = $.extend({

        // Using YQL and the table to query the Flickr API.

        var YQL = '{QUERY}&format=json&callback=?',
            query = "SELECT * FROM{MAX}) WHERE photoset_id='{PHOTOSET}'"+
                " AND api_key='{KEY}'";

        // Replacing the "{EXAMPLE}" keywords from the strings:

        YQL = templateReplace(YQL,{
            "query": encodeURIComponent(
                    photoset : options.photosetID,
                    max : options.maxFetch,
                    key : options.apiKey

        // Template for building Flickr's image URLs:

        var flickrSRC = 'http://farm{FARM}{SERVER}/{ID}_{SECRET}.jpg',
            flickrSlider = this;


        // Fetching the images using Flickr's API:

            if(!r || !r.query || !r.query.count){
                throw "There is no such photoset!";

            var currentPos = 1,
                cnt = r.query.count;

            var caption = $('<span>',{
                className: 'caption'

            var ul = $('<ul>',{
                    width: options.width*r.query.count,

            // Looping through the photo results:

                data = this;

                // Creating a new LI element with the photo as its
                // centered background image:

                    css : {
                        backgroundImage: 'url('+templateReplace(flickrSRC,data)+')',
                        width: options.width


            // Binding a custom "slide" event.
            // You can then flickrSlider.trigger("slide",2)
            // to go to the second slide:

                if(slide < 1 || slide > cnt ||':animated')){
                    return false;

                    easing: 'easeInOutCirc',
                    duration: 300


                    // Animating the transition between
                    // the captions (if enabled):


                currentPos = slide;

            var arrows = $('<div>',{
                className: 'arrows'

            // Creating the previous / next arrows, and
            // binding event listeners for the click events:

            var arrowPrev = $('<a>',{
                className: 'previous',
                href: '#',
                click : function(){
                    var toShow = currentPos - 1;
                    if(toShow < 1){
                        toShow = cnt;

                    return false;

            var arrowNext = $('<a>',{
                className: 'next',
                href: '#',
                click : function(){
                    var toShow = currentPos + 1;
                    if(toShow > cnt){
                        toShow = 1;

                    return false;


            // Showing the first slide by default:



                // If auto advance is enabled, listen for
                // the load event and schedule a periodic slide change.
                // Read more here:


                    $.fn.jqFlick.timeOut = null;


                    (function autoAdvance(){
                        $.fn.jqFlick.timeOut = setTimeout(autoAdvance,options.advancePeriod);

        // This custom event removes all event listeners,
        // and empties the slider holder:


            flickrSlider.empty().unbind('jqFlickRemove slide');


        return flickrSlider;


    // Helper function for replacing "{KEYWORD}" with
    // the respectful values of an object:

    function templateReplace(template,data){
        return template.replace(/{([^}]+)}/g,function(match,group){
            return data[group.toLowerCase()];

    // A custom easing functon. For more info visit:

    $.easing.easeInOutCirc = function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
        return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;


jqFlick takes an options object as its only parameter. You are required to specify the id of the photoset (the photosetID property), which you can easily copy from the address bar of your web browser while viewing the photoset. Only public photosets can be shown by the jqFlick.

Now lets see how the plugin is called. At the top of this file, you will need to paste your Flickr API key that we generated above:



    // Paste your Flickr API key here
    var apiKey = '';

    // Creating a flickr slider. This is
    // how you would probably use the plugin.

        photosetID: '72157625956932639',

    // Creating different flickr sliders,
    // depending on the select element value.


        var options = {};

            case '1':
                options = {
                    photosetID: '72157625956932639',
            case '2':
                options = {
            case '3':
                options = {



In the switch statement above, I am listening for the change event of the select dropdown. There, depending on the value of the select, I assign different options objects, which are then passed to the plugin. This demonstrates the different options that are available without taking much screen space.

With this our Flickr-powered Slideshow is complete!


You can use this plugin to build slideshows, product guides or presentations. To use the plugin you just need to drop the jqFlickr folder to your website root and include jqFlick.css and jqFlick.js in your HTML documents.

Bootstrap Studio

The revolutionary web design tool for creating responsive websites and apps.

Learn more

Related Articles

Very nice bit of jQuerying there, I'll have a play =) Thanks

Alex Flueras

Useful, simple and nice plugin. Thanks for sharing!

Simple, useful and power plugin....
Nice tut and thanks

Simple, yet capable. This deserves the official awesomesauce label!


I love that you don't need an api key for this to work and it pulls more than 20 pix as well. Totally great plugin and I would love to be able to add thumbs to it but don't really know where to start!!

Thank you!

Simple, clean and just the thing i was looking for, for about a week!

Jeremy Bayone

Yes, e11world, nice that you don't need an api key. Maybe useful in the future, but I don't see myself using it now since no sites I've done recently really utilize Flickr. Thanks though for this tut.

Lasse Jensen

Anybody else having trouble with making the images bigger?
I edited everywhere possible, but the images is still only 500 px wide...

Lasse Jensen

Any news on making the images bigger?

love it, but im also having some trouble making the photos bigger. for my site i would like to have 647x431px but everything i have tried still only places the images in a square that im pretty sure is 500px.

I've gone through all the code several times except the jquery.min.js which im unable to edit...

@ Lassee and @Jared

The flickr feed itself sets the sizes of the images. I am not sure if you can use a pipe to change the feed and set the appropriate size, but its worth a shot. The feed specifies different sizes _s,_m,_l,_o,_z. You can check the flickr api for more information on this.

But, you would need to have a script to resize the images as they are loaded onto the page -- specifically one that can resize proportionally. There is one jquery slidershow that does just this, "Supersized!", however, it wasn't meant as a typical slideshow, BUT, you can rework the css to place the slideshow within a container of whatever size you need (its originally meant as a background slideshow).

The problem with flickr and one has created a slideshow/slider/plugin specifically for uh slideshows. There are plenty of plugins that pull from the api to display images, thumbs, or the original size of the image. There used to be a plugin called "Galleria" (and i think you can still download it), that uses the flickr api, and allows images to be resized, however, the developers of that project have stopped supporting it. blah blah blah

Justin MacLeod

I have been using this awesome plugin for a bit now and today I noticed it was returning the error "There is no such photoset!". The thing is I can see the photoset on the Flickr website and everything appears fine. I also see the exact same error happening on the demo. I wonder if Flickr/Yahoo have changed something?


Justin, my Flickr slider just recently stopped working. I'm wondering if something has changed too... The demo isn't even working.

I use this picture rotator on a nonprofit organization's site. One fundraiser is a golf scramble. Every year they take pictures. Before I started working on their site they simply had a stack of pictures on the past scramble pages. The pictures are now pulled from flicker and individually captioned (They were not before.) On flickers interface it is easy to caption, rearrange and categorize pictures into sets. I actually modified the script to parse the url for a phrase and a year. The phrase and year determines what set of pictures the script will pull. It's pretty helpful!
I have found two other flicker picture rotator's but this one is the easiest to work with, along with being the best in my opinion!

One more thing. Some of the past comments have been saying that the picture rotator is giving errors and is broken. Martin (the author of this code) has fixed this problem and it works great now.

I've found this and thought it would be a great fit for a website I'm building. The only problem I'm having is that for some reason the autoAdvance option doesn't work in IE. Any ideas why? It works in other browsers...and your autoAdvance tutorial ( works in IE but the code built into this script doesn't. Any help would be greatly appreciated. Thanks!

I'm new to javascript would you please explain what to do with =

I'm not sure what to replace or where to find the info.

Thank you in advance.

any pointers on how to make the other two sliders autoadvance.

Jon Bukiewicz

For anyone that is looking for help on bringing in other image sizes, check out this URL: link.

Basically, you'll want to find this line in jqFlick.js:

var flickrSRC = 'http://farm{FARM}{SERVER}/{ID}_{SECRET}.jpg',

After the {SECRET} add a letter to represent the size you want the image imported as.

Such as {SECRET}_z.jpg, {SECRET}_m.jpg

s small square 75x75
q large square 150x150
t thumbnail, 100 on longest side
m small, 240 on longest side
n small, 320 on longest side

  • medium, 500 on longest side
    z medium 640, 640 on longest side
    b large, 1024 on longest side*
    o original image, either a jpg, gif or png, depending on source format
Kerry Griggs

I have everything working and can resize the images using the method Jon Bukiewicz described. That works great for everything except original images. Just putting in the _o does not work.

I was able to obtain the values (ex. farm-id: 1, server-id: 2, photo-id:, 1418878, secret: 1e92283336, size: m) for my images but where does that information go?

@ Kerry

I think the _o images only work with an »pro« account due to the limited original images rights in the free account.

But I haven’t tried.

Your slideshow does not work correctly with the latest jquery.
The problem is with:
className: 'caption'

In my browser it just creates the span with 'className' attribute, instead of 'class'.

Just Web Design

Love this slideshow, but had the same problem where it doesn't work properly with the latest version of Jquery, so had to go back to version 1.5 which isn't ideal.

Any chance it could be updated please?

Hi, thanks for a great tutorial!
I've implementet the slideshow on my page, and the images loads and slides perfectly. Only thing I can't figure out is the images seems a little off.

I've taken a screenshot to try to illustrate it:

In the screenshot there, I have drawn a red rectangle around the problem.
The slideshow can be seen at my experimental page

Hope someone can help me with this issue.


OK, not mutch response here.
I've discovered that this problem occures when I use the _z parameter to get large photos from Flickr. Is there anyway to resolve this without removing the _z parameter?


  • Thor

I like this plugin so much, thank you!

Lovely slider - great work!

Is it possible to get the autoadvance to be set to true after a user interaction on the next/prev button? By defualt it stops when the user presses next/prev - How can I fire the function to get autoplay to restart following the button press? Perhaps have a toggle button for autoadvance?

Snippet is currently not working, change requests to Flickr:
" // Using YQL and the table to query the Flickr API.

    var YQL = '{QUERY}&amp;format=json',
        query = &quot;SELECT * FROM{MAX}) WHERE photoset_id='{PHOTOSET}' AND api_key='{KEY}'&quot;;&quot;

'className' rename 'class'