Random images from flickr feed
Hi all
I have adapted some code to import thumbnails from a flickr account
http://www.ttmt.org.uk/flickr/flickr.html
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>untitled</title> <style type="text/css"> *{ margin:0; padding:0; } #images{ margin:30px; } #images ul{ list-style:none; } #images ul li{ float:left; margin-left:10px; } </style> </head> <body> <div id="images"> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"type="text/javascript"></script> <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=59807924@N02&lang=en-us&format=json&jsoncallback=?", displayImages); function displayImages(data) { var count = 0; var htmlString = "<ul>"; $.each(data.items, function(i,item){ if(count <= 3){ var img = (item.media.m).replace("_m.jpg", "_s.jpg"); htmlString += '<li><a href="' + item.link + '" target="_blank">'; htmlString += '<img src="' + img + '" alt="' + item.title + '" title="' + item.title + '"/>'; htmlString += '</a></li>'; } count++; }); $('#images').html(htmlString + "</ul>"); } </script> </body> </html>
This code will load the first 4 images from the flickr photos
What I want to do is randomly load 4 images so they won't always be the same.
I tried this: http://www.ttmt.org.uk/flickr/flickr_ran.html
It's not working and only seems to loop twice
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>untitled</title> <style type="text/css"> *{ margin:0; padding:0; } #images{ margin:30px; } #images ul{ list-style:none; } #images ul li{ float:left; margin-left:10px; } </style> </head> <body> <div id="images"> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"type="text/javascript"></script> <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=59807924@N02&lang=en-us&format=json&jsoncallback=?", displayImages); var count = 0; var htmlString = "<ul>"; function displayImages(data){ alert(count); if(count <= 10){ var ranNum = Math.floor(Math.random()*($(data.items).size())); var img = (data.items[ranNum].media.m).replace("_m.jpg", "_s.jpg"); var link = data.items[ranNum].link; var title = data.items[ranNum].title; htmlString += '<li><a href="' + link + '" target="_blank">'; htmlString += '<img src="' + img + '" alt="' + title + '" title="' + title + '"/>'; htmlString += '</a></li>'; count++; displayImages() }else{ $('#images').html(htmlString + "</ul>"); } } </script> </body> </html>




Bookmarks