2012-04-19 2 views
0

내 이미지에 jQuery 효과를 사용하고 있습니다. 하지만 더 많은 버튼을 클릭하면 JQuery의 다음 이미지가 작동하지 않습니다. 문제는 Dom 준비입니다. 그래서 .live와 함께 jQuery 코드를 사용하고 싶지만 .live를 사용하는 방법을 모른다..live와 함께이 jQuery 코드를 사용하는 방법은 무엇입니까?

도와주세요.

1 :

 var hoverImg = '<div class="hoverimg"></div>'; 

$(".thumb").each(function(){ 
    $(this).children("div").each(function(){ 
     $(this).find("a").append(hoverImg); 
    }); 
}); 

$(".thumb div").hover(function() { 
    $(this).find(".hoverimg").animate({ opacity: 'toggle' }); 
}); 

$(".thumb").hover(function() { 
    $(this).find("div").each(function(){ 
     $(this).find(".shadow").fadeOut(500); 
    }); 
}); 

2 :

var shadowImg = '<div class="shadow"></div>'; 

$(".thumb").each(function(){ 
    $(this).children("div").each(function(){ 
     $(this).append(shadowImg); 
    }); 
}); 

3 : 대신

var c = ''; 
var d = ''; 
$('.view-content div.views-row').each(function(){ 
    c = 0; 
    d = 0; 
    var i = 1; 
    d = $(this).find('.thumbimg').length; 
    $(this).find('.thumbimg').each(function(){ 
     sayi=i++; 
     $(this).append('<div class="img_no">0'+sayi+'</div>'); 
    }); 
}); 

답변

0

사용 on(). jQuery를 1.7로서

$(".thumb div").on("hover", function() { 
    $(this).find(".hoverimg").animate({ opacity: 'toggle' }); 
}); 

$(".thumb").on("hover", function() { 
    $(this).find("div").each(function(){ 
     $(this).find(".shadow").fadeOut(500); 
    }); 
}); 
+0

감사합니다.하지만 여전히 문제가 있습니다. 내 코드에 .live를 적용 할 수 있습니까? – Karmacoma

+0

@ user1213807 내 게시물을 참조하십시오. – sp00m

+0

내 게시물 및 코드를 수정했습니다. 다시 보시겠습니까? – Karmacoma

1

1.

는 .live() 메소드는 추천된다. 이벤트 처리기를 연결하려면 .on()을 사용하십시오.

작동 방식은 다음과 같이이다 :

$('#select_something_static').on("click", ".something_dynamic", {'anydata':True}, handler); 

그런 다음 DOM (동적 노드의 상승)의 정적 최상위 요소 "의"전화 및 동적 노드를 선택합니다. ascend에 대한 이벤트 트리거시 jquery가 selector (".something_dynamic"내 경우)를 검색하고 이벤트가 트리거 된 경우 handler를 호출하고 event.data의 데이터 ({ 'anydata': True})를 넣습니다.

+0

감사합니다.하지만 여전히 문제가 있습니다. 내 코드에 .live를 적용 할 수 있습니까? – Karmacoma

관련 문제