如何在这个插件上使用jQuery .live

时间:2011-03-09 05:51:47

标签: jquery

我正在通过ajax加载一些内容,需要使用live()函数。由于以下插件具有设置属性的属性,因此如何将其设置为使用live()

$(function () {
        $("#book-wrapper .books").hoverIntent({
            over: enter,
            out: leave,
            interval: 200
        });
    });
    function enter() { $(this).animate({ width: '+=115px' }, 350, 'swing'); $(".slide-out", this).animate({ opacity: 1 }, 450, 'swing'); }
    function leave() { $(this).animate({ width: '-=115px' }, 350, 'swing'); $(".slide-out", this).animate({ opacity: 0.0 }, 450, 'swing'); }

2 个答案:

答案 0 :(得分:2)

鉴于您的上述说明 - 您可能实际上并不需要live ...因为bind会为您执行此操作。还存在其他一些插件,包括livequery

$(function(){
  $('html').bind('myhoverintent',function(){
        $('#book-wrapper .books').hoverIntent({
            over: enter,
            out: leave,
            interval: 200
        }); //fixed syntax error
});

//then, later in your method that adds .books:

$('html').append('<div class="books">test</div').trigger('myhoverintent');

如果您添加图书的方法是jQuery ajax方法的结果,那么更简单的方法是,您可以在success的{​​{1}}方法上重新调用原始选择器

答案 1 :(得分:-2)

试试这个,

$(function () {
        $("#book-wrapper .books").live("hoverIntent",function(){
            over: enter,
            out: leave,
            interval: 200
        });
    });
    function enter() { $(this).animate({ width: '+=115px' }, 350, 'swing'); $(".slide-out", this).animate({ opacity: 1 }, 450, 'swing'); }
    function leave() { $(this).animate({ width: '-=115px' }, 350, 'swing'); $(".slide-out", this).animate({ opacity: 0.0 }, 450, 'swing'); }
相关问题