2011-03-09 3 views
1

ajax를 통해 콘텐츠를로드 중이므로 live() 함수를 사용해야합니다. 다음 플러그인은 속성을 설정하여 어떻게 live()을 사용하도록 설정 했습니까? 당신의 위의 설명을 감안할 때이 플러그인에서 jQuery .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'); } 
+0

당신은 모든 새로운'.books'에'hoverIntent' 방법을 추가하려고? – philwinkle

+0

@philwinkle, 예, 페이지로드시 클래스 '.books'에는 이러한 요소가 없습니다. 그것들은 아약스를 통해로드 될 것이고, 나는 그들에게 호버에 반응해야한다. –

답변

2

-bind로 실제로 live을 필요로하지 않을 수 있습니다 ... 당신을 위해이 작업을 수행합니다. 일부 다른 플러그인은 포함뿐만 아니라, 이렇게 존재 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

+0

@philwinkle, 준비 함수 안에있는 부분은 자바 스크립트가 앱에서 작동하지 않게합니다. –

+0

사실 구문 오류가 발견되어 업데이트되었습니다. 여기에 몇 가지 의사 코드 예제가 있습니다 : http://jsfiddle.net/philwinkle/XQaRN/ – philwinkle

+0

@philwinkle, 나는'$ .ajax' 성공 함수 인 duh에 넣을 생각조차하지 않았습니다 :/ –

-2

success 방법은

$(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

함수 내부의 매개 변수는 구문을 사용하여 변수라고 생각할 수 있지만 작동하지 않습니다. –

+0

@ 닉. . 예, 함수 내부의 매개 변수에 대해 알지 못했습니다. 죄송합니다 :) – kushalbhaktajoshi

관련 문제