2013-04-30 15 views
5

マウスを別の要素(リンク)にスライドさせると、マウスが動かないようにする方法を知る必要があります。特定の要素を入力していない場合に、マウス放棄アニメーションのみを行うという条件を設定するにはどうすればよいですか?別の特定の要素を入力するときにjQuery Mouseleaveイベントを停止する

$(activity_link).mouseenter(function() { 
    $(this).siblings(".delete_place").animate({ 
               "left" : "-28px" 
               }, 300);  
}).mouseleave(function() { 
    $(this).siblings(".delete_place").animate({ 
               "left" : 0 
               }, 300); 
}); 
+2

あなたのhtmlとの細目を含むように役立つだろうこの要素。多くの場合、この要素を主要素の子要素にして絶対的に配置します。しかし、これは詳細に非常に依存しています。 –

+0

'.mouseenter'と' .mouseleave'よりも全体的な問題を解決する良い方法があるかもしれないので、あなたの質問にもう少し追加するべきでしょう。 – CaptainBli

答えて

0

あなたがイベントを停止し、バブリング/発火を防ぐことができます:イベントrelatedTargetの

... 
}).mouseleave(function(event) { 
    if(mycondition) { 
     $(this).siblings(".delete_place").animate({"left" : 0}, 300); 
    } else { 
     event.preventDefault(); 
    } 
    ... 
+4

私は "mycondition"として何を書いているのでしょうか? –

4

用途:

$(activity_link).mouseenter(function() { 
    $(this).siblings(".delete_place").animate({ 
     "left": "-28px" 
    }, 300); 
}).mouseleave(function (e) { 
    if (e.relatedTarget != myElem) { //where myElem is a HTML element 
     $(this).siblings(".delete_place").animate({ 
      "left": 0 
     }, 300); 
    } 
}); 
+0

relatedTargetは本当に素晴らしいです!ありがとう:) – ravbetsky

+0

この場合、 'mouseleave'イベントは' myElem'を離れるときに再び実行されません。私はあなたのマウスが 'activity_link'か' myElem'のいずれかを離れるときに実行されるべきだと思います。何か解決策はありますか?私はまったく同じ質問をしているので(https://stackoverflow.com/questions/45126197/how-can-i-select-everything-except-specific-element)。 – stack

関連する問題