开发者

How to use jQuery .live on this plugin

开发者 https://www.devze.com 2023-02-15 12:49 出处:网络
I\'m loading some content via ajax and need to use the live() function. Since the following plugin has properties to set how do you set it up to use live()?

I'm loading some content via ajax and need to use the live() function. Since the following plugin has properties to set how do you set it up to use 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'); }


Given your above clarification - you may not actually need live... as bind does this for you. Some other plugins exist that do this as well, including 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');

Even simpler would be if your method to add books comes as a result of a jQuery ajax method, you could just re-call your original selector on the success method of $.ajax


Try this,

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

精彩评论

暂无评论...
验证码 换一张
取 消