2012-04-19 43 views
0

我在圖片上使用了一些jQuery效果。但是當我點擊加載更多按鈕時,請不要使用JQuery下一張圖片。問題是Dom準備好了。所以,我想用我的jQuery代碼與.live,但我不知道如何使用.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()代替。

1.

$(".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 2012-04-19 14:20:14

+0

@ user1213807查看我的帖子。 – sp00m 2012-04-19 14:23:33

+0

編輯我的帖子和代碼。請再看一遍? – Karmacoma 2012-04-19 14:41:41

1

在jQuery 1.7的,所述.live()方法被棄用。使用.on()附加事件處理程序。

它的工作方式是這樣的:

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

您DOM(動態節點的長輩)的靜態頂級元素上所說的「上」,然後選擇動態節點。當事件觸發上升時,jquery搜索選擇器(在我的情況下爲「.something_dynamic」),如果它觸發,則調用處理程序並將數據放入event.data中({'anydata':True})

+0

謝謝你,但仍然有問題。你可以在我的代碼上申請.live嗎? – Karmacoma 2012-04-19 14:07:03