0
Ok ..私はいくつかの同様の質問がありますが、私はそれらを読んだが、私のコードはまだglitchyです。同じコンテナの中にイメージとテキストがあります。テキストがフェードアウトすると、画像がフェードインするはずです。 また、内部に画像とテキストを含む複数のコンテナがあります。jqueryでホバー上の複数のアニメーションのダブルループを停止します
私は動作するコードを持っていますが、実際には見苦しく見えますが、うまく動作しないようです。これを改善する方法の提案?コード http://jsfiddle.net/pedromvpg/ekbf2/
:ここ
は実施例である
$(function() {
function image_pulse(element){
element.animate({opacity:0.3}, 700, function(){
element.animate({opacity:1}, 700, function(){
element.animate({opacity:0.3}, 700, image_pulse(element));
});
});
}
function text_pulse(element){
element.animate({opacity:1}, 700, function(){
element.animate({opacity:0}, 700, function(){
element.animate({opacity:1}, 700, text_pulse(element));
});
});
}
$('.pulser_new').each(function (i) {
text_pulse($(this).children('.fader_title'));
image_pulse($(this).children('.fader_image'));
});
$('.pulser_new').hover(
function() {
$(this).children('.fader_image').stop();
$(this).children('.fader_image').animate({opacity:0.3},700);
$(this).children('.fader_title').stop();
$(this).children('.fader_title').animate({opacity:1},700);
//alert("in");
},
function() {
image_pulse($(this).children('.fader_image'));
text_pulse($(this).children('.fader_title'));
//alert("out");
}
);
})。
ありがとうございます!
Hiya、わずか数はアドバイス - することができます。すなわち1)、jQueryの中で、連鎖について読みます要素内の関数間を連鎖させます。これにより、同じ要素への複数のイベントバインディング行が回避されます。また2)私は通常DRYに従います(あなた自身の原則を繰り返さないでください)。つまり、あなたがあなたの "code" text_pulse($(this).children( '.fader_title'))のために共通の関数を作ることができます。 image_pulse($(this).children( '。fader_image'));私はこれらのヒントがかなり役に立ちました。 http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx;それがあなたに良い、有益な情報を提供してくれることを願っています。 –