TwitpicのRSSフィードを取得して投稿した写真を一覧表示(最新9件のみ取得)。
サムネイルにマウスオーバーするとズームアップし、クリックするとTwitPicの写真ページに遷移します。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>設置サンプル</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script type="text/javascript" src="/content/lib/jquery/jfeed/jquery.jfeed_twitpic.js"></script> <script type="text/javascript"> $(function(){ $.getFeed({ /* TwitPicのRSSフィードを取得 */ url: "/content/lib/jquery/jfeed/proxy.php?url=http://twitpic.com/photos/cocoism/feed.rss", success:function(xml){ /* RSSフィードのタイトル */ $("#gallery h2").html("<a href='"+xml.link+"'>"+xml.title+"</a>"); if(xml.items.length<1){ /* 1件もない場合 */ $("#gallery ol").html("<li>情報がありません。</li>"); }else{ /* 写真一覧HTML生成 */ $(xml.items).each(function(i, item){ if(i>=9) return; var _link=item.link; $("#gallery ol").append("<li><a href='"+_link+"'>"+formatString(_link)+"</a></li>"); }); } } }); }); /* リンクのフォーマット */ function formatString(str){ /* サムネイル画像リンク生成 */ str=str.replace(/(http:\/\/twitpic\.com\/)(\w*)/gm,'<a href="'+str+'" target="_blank"><img src="http://twitpic.com/show/thumb/$2" /></a>'); return str; } function relativeTime(pastTime){ var origStamp = Date.parse(pastTime); var curDate = new Date(); var currentStamp = curDate.getTime(); var difference = parseInt((currentStamp - origStamp)/1000); if(difference < 0) return false; if(difference <= 5) return "いまさっき"; if(difference <= 20) return "数秒前"; if(difference <= 60) return "1分以内"; if(difference < 3600) return parseInt(difference/60)+" 分前"; if(difference <= 1.5*3600) return "One hour ago"; if(difference < 23.5*3600) return Math.round(difference/3600)+" 時間前"; if(difference < 1.5*24*3600) return "1日前"; var dateArr = pastTime.split(' '); return (parseInt(difference / 86400)).toString() + '日前'; } </script> <style type="text/css"> #gallery { margin:0 auto; padding:0; } #gallery ol { list-style:none; margin:0; padding:0; } #gallery li { display:block; list-style:none; float:left; margin:5px; padding:0; position:relative; width:85px; height:85px; } #gallery li a { position:relative; } #gallery li a img { position:absolute; -webkit-transition: .3s ease-in-out; width:75px; height:75px; overflow:hidden; background:#fff; border:1px solid #ccc; margin:0; padding:5px; -webkit-border-radius:5px;-moz-border-radius:5px; z-index:100; } #gallery li a:hover img { width:120px; height:120px; top:-25px; left:-25px; z-index:200; } </style> <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head> <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <h1>設置サンプル</h1> <p>TwitpicのRSSフィードを取得して投稿した写真を一覧表示(最新9件のみ取得)。<br>サムネイルにマウスオーバーするとズームアップし、クリックするとTwitPicの写真ページに遷移します。</p> <!-- CODE --> <div id="gallery"> <h2></h2> <ol class="cf"></ol> </div> <!-- CODE / --> </div> </body> </html>