2011-01-18 15 views
3

実簡単な質問 - 私は.live("hover", function.live機能に「hoverIntent」を追加

 $(".highlight").live("hover", function(){ 
      $(this).animate({"width": "454px", "height":"282px", "top: ":"94px", "left":"152px", "margin-top: ":"-94px", "margin-left":"-152px"}, 500);  

     }); 

の代わりに、次のコードにブライアンCherneから.hoverIntent pluginを追加するにはどうすればよいここでは完全なコードです:

$(document).ready(function(){   

     $('#sliding_grid li').hover(function() { 
      $(this).css('z-index',1).data('origTop',$(this).css('top')).data('origLeft',$(this).css('left')).addClass('highlight'); 

     }, function() { 
      $(this).css('z-index', 0); 
     }); 

     $(".highlight").live("hover", function(){ 
      $(this).animate({"width": "454px", "height":"282px", "top: ":"94px", "left":"152px", "margin-top: ":"0", "margin-left":"0"}, 500);  

     }); 

     $(".highlight").live("mouseout", function(){ 
      $(this).animate({"width": "148px", "height":"90px", "top: ":$(this).data('origTop'), "left":$(this).data('origLeft'), "margin-top: ":"0", "margin-left":"0"}, 500, function(){ 
      $(this).removeClass('highlight'); 
      });   

     });   

    }); 
+5

hernan on githubそれをforkしてプラグインにサポートを追加したので、コードを変更せずにライブイベントにバインドします。 https://github.com/hernan/hoverIntent commit - https://github.com/hernan/hoverIntent/commit/c35a71a92278792d70845c711c41c5b9e909b848 – jBeas

答えて

2
function animateFn(){ 
    $(this).animate({"width": "454px", "height":"282px", "top: ":"94px", "left":"152px", "margin-top: ":"-94px", "margin-left":"-152px"},200); 
} 

function reseteFn(){ 
    $(this).animate({"width": "148px", "height":"90px", "top: ":$(this).data('origTop'), "left":$(this).data('origLeft'), "margin-top: ":"0", "margin-left":"0"}, 500, function(){ 
     $(this).removeClass('highlight'); 
    }); 
} 

var config = {  
    over: animateFn, // function = onMouseOver callback (REQUIRED)  
    timeout: 200, // number = milliseconds delay before onMouseOut  
    out: reseteFn // function = onMouseOut callback (REQUIRED)  
}; 

$(".highlight").hoverIntent(config) 
+0

ダイスはありません:(ここにコードが公開されています:http://jsfiddle.net/kTFvj/3/ – Brian

+0

私は5分でそれをチェックするつもりです;)私はあなたにお知らせします – stecb

+0

どこに浮気libですか?また、コードが間違っています。あなたは '$( "。ハイライト")を設定する必要があります。hoverIntent(config);' ( "mouseout"、function(){... ' – stecb

4

このコードを交換してみてください:

$(".highlight").live("hover", function(){ 
    $(this).animate({"width": "454px", "height":"282px", "top: ":"94px", "left":"152px", "margin-top: ":"0", "margin-left":"0"}, 500);  

}); 
これにより

:この答えのよう

$('.highlight').live('mouseover', function() { 
    if (!$(this).data('init')) { 
    $(this).data('init', true); 
    $(this).hoverIntent(function(){ 
     $(this).animate({"width": "454px", "height":"282px", "top: ":"94px", "left":"152px", "margin-top: ":"0", "margin-left":"0"}, 500); 
    }, 
    function(){ 
     /* mouseout logic */ 
    }); 
    $(this).trigger('mouseover'); 
    } 
}); 

Source

+1

これは本当に醜い処理方法です。それがうまくいかないとは言わないだろう...しかし、それは私が泣きたい。 :) – gnarf

+0

Not working :(あなたのコードがソースにプラグインされています:http://jsfiddle.net/kTFvj/4/ – Brian

5

、プラグインの現在のバージョンはここで見つけることができる "R7" である:バージョンで

http://cherne.net/brian/resources/jquery.hoverIntent.r7.js

"r7"では、セレクタを3番目のパラメータとして渡すことができます。これはjQueryのdelegate eventと似ています。動的要素のリストにhoverIntentを追加する場合は、hoverIntentイベントを親要素にバインドし、3番目のパラメータを使用して、hoverIntentを使用する要素のセレクタを追加します。あなたが変更されます<li>要素のリストを持っているとあなたはhoverIntentは各<li>上で起動するようにしたいならば、あなたは次の操作を行うことができる。例えば

、:

$("ul").hoverIntent(overFunction, outFunction, "li"); 

これは非常に基本的なものですので、あなたが希望正確な設定に合わせて2つのセレクタを更新したいと考えています。

+0

++++あなたが読んでいた/あなたの完全に驚くべき答えを見つける前に、あなたのお手伝いをしてください。ありがとう! –

+0

マシューを助けてくれてうれしい! –

関連する問題