2012-04-10 8 views
1

マウスが画像の上にあり、マウスの右ボタンが押されているときに画像をズームする必要があります。次のようなものがあります。マウスの右ボタンが押されていれば何かをする

$('img').hover(
    function(){ 
     if (the-right-mouse-button-is-pressed){ 
     $(this).animate({ 
     width: $(this).width() *2, 
     height: $(this).height()*2, 
     }, 500); 
     } 
    }, 
}); 

私は助けが必要です。ありがとう。

+0

検索のリル・ビット.... http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery、 http://stackoverflow.com/questions/706655/bind-event-to-right-mouse-click、http://stackoverflow.com/questions/4007482/jquery-detect-if-ミドルまたはライト - マウス - ボタンをクリックしたら、これは – elclanrs

+0

私はそれを見ました。それは私の質問とは違う。途中でありがとう。 –

答えて

2

編集:あなたの以下のコメントについては

感謝。ただし、画像を右クリックする必要があります。あなたが画面 のどこか下の右ボタンを維持し、その後、あなたは条件付きでmouseUpイベントやズームを追加する必要があり、画像

を渡した場合、それはない 作業を行います。あなたはホバーを通じて達成することはできません必要なものDEMO

var hasExpanded = false; 
$('img').on('mousedown mouseup', function(e) { 
    if (e.which == 3) { 
      if (!hasExpanded) { 
      $(this).animate({ 
       width: $(this).width() * 2, 
       height: $(this).height() * 2, 
      }, 500); 
     } 
     hasExpanded = true; 
    } 
}).mouseleave(function(e) { 
    if (hasExpanded == true) { 
    $(this).animate({ 
     width: $(this).width()/2, 
     height: $(this).height()/2, 
    }, 500); 
    hasExpanded = false; 
} 
}); 

、コードの下を参照してください。ホバーはmouseeneterでトリガーされ、1回だけ呼び出され、後で発生するmousedownイベントは記録できません。

mousedownハンドラを実装する必要があります。下記を参照してください

DEMO - デモはmousedownmouseleaveの両方を実装しています。

$('img').mousedown(function(e) { 
    if (e.which == 3) { 
     $(this).animate({ 
      width: $(this).width() * 2, 
      height: $(this).height() * 2, 
     }, 500); 
    } 
}); 
+0

ありがとうございます。ただし、画像を右クリックする必要があります。右のボタンを画面の他の場所に置いて、画像を渡すと機能しません。 –

+0

@BaharS画像上でマウスアップケースを処理するコードを更新しました。 [** DEMO **](http://jsfiddle.net/PhM8P/3/)。 –

関連する問題