質問

Im有の問題です。これが私のサイト http://keironlowe.x10hosting.com/ 赤のライン移動のナビゲーションバーによるこのコードです。が働いていないことがあります。何をしたいのですが、赤い線を得なホバー.が戻通常サイズのカーソルを動かす、 それだけではありません。でのみ動作しまいリフレッシュで作にリンクが小さくなります。す。

<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
 $('div', '#nav_container').hover(function() {
    $(this).animate({width: '220px'}, 1000);      
}, function() {
    $(this).animate({width: '300px'}, 1000); 
});
});
</script>
役に立ちましたか?

解決

み呼び出し .stop() 前のアニメーション:

$(document).ready(function() {
  $('div', '#nav_container').hover(function() {
    $(this).stop();
    $(this).animate({width: '220px'}, 1000);      
  }, function() {
    $(this).stop();
    $(this).animate({width: '300px'}, 1000); 
  });
});

編集: したい場合はサイズを変更画像の代わりに本部が含まれています。してみてください:

$(document).ready(function() {
     $('#nav_container div').hover(function() {
        $(this).children('img').stop().animate({width: '220px'}, 1000);      
     }, function() {
        $(this).children('img').stop().animate({width: '300px'}, 1000); 
     });
});

きを調整する必要があるの幅と持続時間をお望み通りの成果を上げている。

他のヒント

その修正やすいメイトます。

スクリプトタグで次のように記述します:

$(document).ready(function() {
        $('.box').hover(
          function() {
              $(this).css({ background: 'blue' });
          },
          function() {
              $(this).css({ background: 'black' });
          }
        );
    });

と、次のマークアップを書き、あなたが持っている必要がありますあなたのホバーあなたに笑顔

<div class="box"></div>

おっと言及するのを忘れてしまいました。 jqueryの中で複数のセレクタを書くことのようです。

( 'selector1、selector2、...')

これはあなたが誤ってように書かれていています:

$( 'DIV'、 '#nav_container')。ホバー(関数(){...

希望はこのことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top