skuare.netはJavaScriptライブラリのjQuery,mootools,prototypeのプラグインを中心にWebサイト構築に関する技術を試す個人サイトです

skuare.netが紹介するJavaScirptでサイトをリッチに

これは面白い!jQueryで紙芝居のように画像をめくるJavaScript

twitterにつぶやく このエントリーを含むはてなブックマーク はてなブックマークを見るこの記事をクリップ! コメントを見るYahoo!ブックマークに登録 このエントリーをdel.icio.usに追加する deliciousブックマーク数このページを行き先登録 このページをniftyクリップに登録このページをBuzzurlに登録

Create a unique Gallery by using z-index and jQueryで紹介されている画像の見せ方が面白いので紹介します。
クリックするたび紙芝居のように画像がめくられていきます。
これは面白い!jQueryで紙芝居のように画像をめくるJavaScriptサンプル

使用方法
jQueryからjquery.jsをダウロードします。
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var z = 0;
var inAnimation = false;
$('#pictures img').each(function() {
z++;
$(this).css('z-index', z);
});
function swapFirstLast(isFirst) {
if(inAnimation) return false;
else inAnimation = true;
var processZindex, direction, newZindex, inDeCrease;
if(isFirst) { processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1; }
else { processZindex = 1; direction = ''; newZindex = z; inDeCrease = -1; }
$('#pictures img').each(function() {
if($(this).css('z-index') == processZindex) {
$(this).animate({ 'top' : direction + $(this).height() + 'px' }, 'slow', function() {
$(this).css('z-index', newZindex)
.animate({ 'top' : '0' }, 'slow', function() {
inAnimation = false;
});
});
} else {
$(this).animate({ 'top' : '0' }, 'slow', function() {
$(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease);
});
}
});
return false;
}
$('#next a').click(function() {
return swapFirstLast(true);
});
$('#prev a').click(function() {
return swapFirstLast(false);
});
});
</script>

上記のようにjsを記述した後、画像を以下のように書けば完成です。
<div id="gallery">
<div id="pictures">
<img src="画像パス" />
<img src="画像パス" />
</div>
<div id="prev">
<a href="#previous">« 前</a>
</div>
<div id="next">
<a href="#next">次 »</a>
</div>
</div>

<これは面白い!jQueryで紙芝居のように画像をめくるJavaScriptサンプル

記事作成:2009年03月24日

follow me

▼これは面白い!jQueryで紙芝居のように画像をめくるJavaScriptへのコメントはtwitterにて受け付けています。
twitterでコメントする twitterでコメントする

前の記事:ポロライド写真をばら撒いたように表示するギャラリーJavaScript「Polaroid Photo Viewer」
次の記事:3ステップでツールチップを作成「jQuery Simple Tooltip」

ページの最初に戻る

about me

skuare

大学卒業後、某PR会社にてPR誌の取材・編集・デザインからPRコンサルティング、調査分析まで幅広い業務に携わる。業務の合間合間にWEB制作に関する技術を習得。
2007年6月から当サイト「skuare.net」を開始。その後、ホームページ制作会社に転職し、WEBサイト制作に本格的に従事し、CMS、JavaScriptに無駄に突っ込むディレクターとして活動中。ホロヨッターもやっています。
もし、もうちょっと詳細を見たかったら・・・・こちら >>

I'm @ Social media below

  • skuare.net rss
  • skuare's twitter
  • skuare's twitter
  • skuare's linkedin
  • skuare's facebook
Copyright (c) skuare.net All Rights Reserved.