2012-04-28 11 views
2

移動背景のjQuery

矢印のデフォルトのCSSの設定は次のとおりです。デフォルトでitem 1下矢印を配置

#arrow { 
    background: url('./arrow-up.png') no-repeat 10px 0; 
} 

次のjQueryコードを作成しましたが、動作しないようです。リンクをクリックしても矢印が動かないときは何も起こりません。

$(document).ready(function(){ 

    $("#menu1").click(function(){ 
     $("#arrow").animate({ 
      background: url('./arrow-up.png') no-repeat 10px 0 
     }, 1500); 
    }); 

    $("#menu2").click(function(){ 
     $("#arrow").animate({ 
      background: url('./arrow-up.png') no-repeat 90px 0 
     }, 1500); 
    }); 

    $("#menu3").click(function(){ 
     $("#arrow").animate({ 
      background: url('./arrow-up.png') no-repeat 180px 0 
     }, 1500); 
    }); 
}); 

これはどのように修正できますか?

答えて

3

あなたはこのプラグインを使用する必要があります。http://www.protofunc.com/scripts/jquery/backgroundPosition/

$('#menu1').click(function(){ 
    $('#arrow') 
     .animate({backgroundPosition:'10px 0'}); 
}); 
+0

それは働いていませんでした。私はそれを変更し、今それは動作します。 (あなたの投稿を編集して申し訳ありませんが、私はあなたの受け入れられた答えを盗みたくありませんでした;-)) –