0

次のコードは私に多くの問題を引き起こしています。.hover は背景画像を変更することに注意してください。まず、別の mouseenter と mouseleave ではなく、2 つを .hover と組み合わせるにはどうすればよいですか? 第二に、divが上にシフトしている間に背景画像が同時にフェードするようにするにはどうすればよいですか?

$('div.designbox.orangehello').mouseenter(function() {
   $('div.designbox.orangehello').animate({
     top: '-=10',
   }, 55, function() {
     $(this).addClass('hover');
   });
 });

 $('div.designbox.orangehello').mouseleave(function() {
   $('div.designbox.orangehello').animate({
     top: '+=10',
   }, 55, function() {
     $(this).removeClass('hover');
   });
 });
4

1 に答える 1

1

を使用して 2 つを結合するには、次の.hover()ようにします。

$('div.designbox.orangehello').hover(function() {
   $(this).animate({ top: '-=10' }, 55, function() {
     $(this).addClass('hover');
   });
}, function() {
   $(this).animate({ top: '+=10' }, 55, function() {
     $(this).removeClass('hover');
   });
});

フェードに関しては、マークアップを投稿する必要があります。追加<div>または他の背景を含むものが必要です。

アニメーションの引数に関するいくつかの注意事項があります{ top: '-=10', }...特に IE では、末尾のコンマに注意してください。特に IE では問題が発生します。また、$('div.designbox.orangehello')これらをたくさんアニメートしている場合は、これを元に戻しますが、現在のもののみが必要な場合$(this)は、上記のように使用します。

于 2010-05-15T07:03:32.710 に答える