これは、stackoverflow に関する私の最初の投稿です。皆さん、こんにちは!
jQuery アニメーションへの私の最初の試みは、上半分と下半分の 2 つの div に一連の画像を配置し、それらをフリップダウン トランジションで回転させることでした。
アニメーションを停止しましたが、ページ上で複数のアニメーションが同時に表示されることが問題です。私の問題は、jQuery セレクターの範囲を理解していないことが原因です。
$(document).ready(function(){
flippers($('.flipper'));
});
function flippers(divs){
divs.each(function(i){
$(".top_container img").each(function (j){
$(this).attr("id",i+"t"+j);
});
$(".bottom_container img").each( function(j){
$(this).attr("id",i+"b"+j);
});
});
var flip_wait = 3600;
setTimeout("flippers_start("+flip_wait+")",flip_wait);
}
function flippers_start(time,flipper){
var curr_top = '#' + $('.top_container img:visible').attr('id');
var curr_bottom = '#' + $('.bottom_container img:visible').attr('id');
if( ($('.top_container img').size() - 1) <= curr_top[3] ){
var next_top = curr_top.substring(0,3) + 0;
var next_bottom = curr_bottom.substring(0,3) + 0;
}
else{
var next_top = curr_top.substring(0,3) + (parseInt(curr_top[3]) + 1);
var next_bottom = curr_bottom.substring(0,3) + (parseInt(curr_bottom[3]) + 1);
}
var height = $(curr_top).height();
var width = $(curr_top).width();
flip(height,width,curr_top,curr_bottom,next_top,next_bottom);
setTimeout("flippers_start("+time+")",time);
}
function flip(height,width,fromtop,frombottom,totop,tobottom){
var fliptime = 250;
$(frombottom).css("z-index","1");
$(tobottom).css("z-index","2");
$(fromtop).css("z-index","2");
$(totop).css("z-index","1");
$(tobottom).css("height","1px").show();
$(totop).show();
$(fromtop).stop().animate({height:'0px',width:''+width+'px',marginTop:''+height+'px'},{duration:fliptime});
window.setTimeout(function() {
$(tobottom).stop().animate({height:''+height+'px',width:''+width+'px',marginBottom:'0px',opacity:'1'},{duration:fliptime});
},fliptime-40);
$(frombottom).slideUp();
window.setTimeout(function(){
$(fromtop).height(height).hide().css("margin-top","0px");
},fliptime*2);
}
これが私が説明した一連の画像で実行されると、
<div class="flipper">
<div class="top_container">
<img src="images/pink_floyd_img/dark1.jpg" class="top first" />
<img src="images/pink_floyd_img/wall1.jpg" class="top second hidden" />
<img src="images/pink_floyd_img/wish1.jpg" class="top third hidden" />
</div>
<div class="bottom_container">
<img src="images/pink_floyd_img/dark2.jpg" class="bottom first" />
<img src="images/pink_floyd_img/wall2.jpg" class="bottom second hidden" />
<img src="images/pink_floyd_img/wish2.jpg" class="bottom third hidden" />
</div>
</div>
期待どおりに動作します。ただし、「フリッパー」divを複製すると、アニメーションは最初のセットで最初に実行され、次に2番目のセットで実行されます。
私はそれが起こったときにアニメーション化する各画像を選択する方法と関係があることを知っていますが、私がしていることを他にどのように行うかは本当にわかりません.
最終的な目標は、適切なクラスでマークアップされた div と画像をまとめて、アニメーションを実行するために動的に ID を設定できるようにすることです。各divの個別の呼び出し(すべてが同時に反転しないように発生する可能性があります)。
ありがとう!