先日のエントリー「jQueryスライド用スクリプトもろもろ。」について
スライドするだけではつまらないとのコメントをいただいたので、
エフェクト的な効果を追加してみました。
画像をスライドさせるのに加えて、
animateに対してopacityを追記してフェード効果を付けることや、
スライドではなく画像が折り畳む(潰れる?)効果に変更してみたり、
応用(?)として「jquery.easing.js」を使って、
スライド後にバウンド効果をつけてみました。
実際は以下のような感じに。
画像にマウスオーバーしてください。
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
改変したスクリプトは以下のような感じに。
◆SCRIPT
$(document).ready(function(){ $('#top-left').hover(function(){ $(this).children('.front').stop().animate({'top' : '150px', 'left' : '300px', 'opacity': '0'}, 500); }, function(){$(this).children('.front').stop().animate({'top' : '0px', 'left' : '0px', 'opacity': '1'}, 500);}); $('#top-center').hover(function(){ $(this).children('.front').stop().animate({'top' : '150px','width' : '300px','height' : '0'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500); }, function(){$(this).children('.front').stop().animate({'top' : '0px','width' : '300px','height' : '150px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500);}); $('#bottom-center').hover(function(){ $(this).children('.front').stop().animate({'top' : '-150px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500); }, function(){$(this).children('.front').stop().animate({'top' : '0px', 'left' : '0px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500);}); $('#left').hover(function(){ $(this).children('.front').stop().animate({'left' : '300px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500); }, function(){$(this).children('.front').stop().animate({'top' : '0px', 'left' : '0px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500);}); $('#right').hover(function(){ $(this).children('.front').stop().animate({'left' : '0','width' : '0','height' : '150px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500); }, function(){$(this).children('.front').stop().animate({'left' : '0px','width' : '300px','height' : '150px'},{queue:false, duration:600, easing: 'easeOutBounce'}, 500);}); $('#top-right').hover(function(){ $(this).children('.front').stop().animate({'top' : '150px','left' : '-300px', 'opacity': '0'}, 500); }, function(){$(this).children('.front').stop().animate({'top' : '0px', 'left' : '0px', 'opacity': '1'}, 500);}); $('#top-left_custom').hover(function(){ $(this).children('.front').stop().animate({'top' : '150px', 'left' : '300px', 'width' : '0', 'height' : '0', 'opacity': '0'}, 500); }, function(){$(this).children('.front').stop().animate({'top' : '0px', 'left' : '0px', 'width' : '300px', 'height' : '150px', 'opacity': '1'}, 500);}); });
ちょっとゴチャゴチャしてしまいましたが、
画像をスライドさせるには‘top’や‘left’で位置を移動していましたが
画像を折り畳むように見せるには‘width’や‘height’の値をanimeteで変化させています。
フェードの効果は先に述べた通りanimateに‘opacity’(透過度)を追加して
「0(透過度100%)」から「1(透過度0%)」に変化させています。
単純なスライドだけでなく、jQueryではさまざまな演出を簡単につけれるところがおもしろい。
今回のサンプルは遊びのようなものですが。。。
ご参考までに。。。