将"hoverIntent"添加到.live函数中

Bri*_*ian 4 javascript jquery jquery-plugins

这里真正简单的问题 - 如何将Brian Cherne 的.hoverIntent插件添加到以下代码中代替.live("hover", function

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

        });   
Run Code Online (Sandbox Code Playgroud)

这是完整的代码:

    $(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');   
            });        

        });        

    });
Run Code Online (Sandbox Code Playgroud)

Tim*_*nks 5

截至这个答案,该插件的当前版本是"r7",可以在这里找到:

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

使用版本"r7",您可以将选择器作为第三个参数传递.这就像jQuery中的委托事件.将hoverIntent添加到动态元素列表时,将hoverIntent事件绑定到父元素,并使用第三个参数添加要使用hoverIntent的元素的选择器.

例如,如果您有一个<li>将要更改的元素列表,并且您希望在每个元素上触发hoverIntent,<li>那么您可以执行以下操作:

$("ul").hoverIntent(overFunction, outFunction, "li");
Run Code Online (Sandbox Code Playgroud)

这是非常基本的,因此您需要更新2个选择器以匹配您的确切设置.