0

ユーザーがクリックして以下のjqueryコードで別の背景画像を選択したときに、スムーズなトランジション効果を持たせようとしていますが、うまくいかないようです。ページのコンテンツではなく、背景画像のみをアニメーション化したいと考えています。

$('.bg1').click(function() {
    ($this).animate({opacity: 0}, 'slow', function() {
    $(this)
        .css({'background-image': 'url(img/bg-2.jpg)'})
        .animate({opacity: 1});
     });
});

ここにフィドルがあります: http://www.jsfiddle.net/Tw8Ph/4

4

3 に答える 3

0

あなたのコードには小さな間違いがあります

HTML コード:

$('.bg1').click(function() {
  $(this).animate({opacity: 0}, 'slow', function() {  
    $(this)
    .css({'background-image': 'url(img/bg-2.jpg)'})
    .animate({opacity: 1});
 });
});

($this).animate({opacity: 0},2行目ではなく、間違いを犯しました $(this).animate({opacity: 0},

ハッピーコーディング:)

于 2013-08-30T14:08:06.930 に答える