Javascript 让jquery插件在Ajax调用后工作
这将是一个很长的帖子,但我真的受够了试图解决这个问题。我真的在找人帮忙解决我的案子 第一名:Javascript 让jquery插件在Ajax调用后工作,javascript,jquery,django,dajaxice,dajax,Javascript,Jquery,Django,Dajaxice,Dajax,这将是一个很长的帖子,但我真的受够了试图解决这个问题。我真的在找人帮忙解决我的案子 第一名: fade.js: $(document).ready(function(){ $(".gallery ul li img.a").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 30% when the page loads $(".gallery ul li img.a").hover(functi
fade.js
:
$(document).ready(function(){
$(".gallery ul li img.a").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 30% when the page loads
$(".gallery ul li img.a").hover(function(){
$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 0.5); // This should set the opacity back to 30% on mouseout
});
});
$(document).ready(function(){
//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
//Full Caption Sliding (Hidden to Visible)
$('.gallery li').hover(function(){
$(".cover", this).stop().animate({top:'106px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'153px'},{queue:false,duration:160});
});
});
这里的问题是在下一页的ajax调用之后,淡入淡出停止工作。所以我所做的是
$(document).ready(function(){
$(".gallery ul li img.a").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 30% when the page loads
$(".gallery ul li img.a").live("hover", function(){
$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 0.5); // This should set the opacity back to 30% on mouseout
});
});
但只有当我将鼠标悬停在图像上时,图像才会淡出。如果我对$(“.gallery ul li img.a”).fadeTo
到.live(…)
做同样的事情,什么都不会发生,它就是不起作用
- 即使在ajax调用之后,如何使其工作呢?ajax调用应该在加载时淡入淡出,然后在我悬停在它上面时淡出
slider.js
:
$(document).ready(function(){
$(".gallery ul li img.a").fadeTo("slow", 0.5); // This sets the opacity of the thumbs to fade down to 30% when the page loads
$(".gallery ul li img.a").hover(function(){
$(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 0.5); // This should set the opacity back to 30% on mouseout
});
});
$(document).ready(function(){
//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
//Full Caption Sliding (Hidden to Visible)
$('.gallery li').hover(function(){
$(".cover", this).stop().animate({top:'106px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'153px'},{queue:false,duration:160});
});
});
我将$('.gallery li').hover(…)
更改为$('.gallery li').live(“hover”,function(){…})
,但仍然不起作用。我还使用了.on
而不是.live
,因为它已被弃用
我做错了什么?我不是一个客户端的家伙,我的大部分工作是服务器端。我只需要在AJAX调用发生后让这两个插件工作
阿贾克斯:
编辑2:
<a href="#" onclick="Dajaxice.gallery.gallerypages(Dajax.process, {'p': {{ items.previous_page_number }},})" class="btn_prev"><b><</b></a>
您的
live
朝着正确的方向前进,但是live
因on
事件而贬值。启用,可以将选择器作为参数之一。初始jQuery选择器只是要向其中添加处理程序的对象的容器
<div id="content">
<div class="sombutton"></div>
</div>
$( document ).ready( function() {
$( '#content' ).on( 'click', '.somebutton', function() {
alert( 'do something' );
} );
} );
$(文档).ready(函数(){
$('content')。在('click','somebutton',function()上{
警惕(‘做某事’);
} );
} );
现在,即使我们替换#conent
div中的内容,新添加的内容也会添加类。somebutton
也会附加一个单击处理程序
我不确定,但测试一下这些东西: 通过jQuery编写JavaScript
var initFade = function() {
$(".gallery ul li img.a").fadeTo("slow", 0.5);
}
// your custom callback method
var reBindStuffs = function(data) {
Dajax.process(data);
// rebind your jquery event handlers here... e.g.
initFade();
};
$(document).ready(function(){
// initial first time loaded fade
initFade();
// hover live binder
$(".gallery ul li img.a").live("hover", function(){
$(this).fadeTo("slow", 1.0);
},function(){
$(this).fadeTo("slow", 0.5);
});
// document keydown listener
$(document).on("keydown", "#pagenumber", function(e)
if ( e.which === 13 ) {
Dajaxice.gallery.gallerypages('reBindStuffs', {'p': this.value});
}});
});
HTML
<!-- a click listener -->
<a href="#" onclick="Dajaxice.gallery.gallerypages(reBindStuffs, {'p': {{ items.previous_page_number }},})" class="btn_prev"><b><</b></a>
你提到的是一个大问题,我手工刷新。但我也使用.ajax完整的功能。它在每次Ajax查询之后运行
$(document).ajaxComplete(function(){
// Carga tabs por defecto por clases.
if (typeof jQuery.fn.wf_responsivetab == 'function')
{
if ($('#rbtt_1').length)
{
$('#rbtt_1').wf_responsivetab({text: '...',});
$(window).on('resize', function() {$('#rbtt_1').wf_responsivetab({text: '...',});});
}
}
});
Ajax调用到底在做什么?很抱歉,我没有提到这一点,Ajax调用只会加载库中的下一页,我在一个div中有一个图像列表。在Ajax调用完成后重新运行fade.js。在Ajax调用完成后如何重新运行它?我要指出的是,我使用的是Dajax而不是Ajax,它是针对Django的Ajax。这有点不一样,如果成功了什么的话。如果我能在调用后运行一个函数,我现在会检查它。我希望它有一个事件:)另外,如果你不使用jQuery将内容添加到你的页面,我不确定
上的事件是否能按预期工作。也许可以尝试使用jQuery来实现ajax并将内容加载到div中。为了清楚起见,您不必将选择器传递给on()
。如果要在元素上直接注册侦听器,则不传递选择器。当您需要委托事件注册时,您会传递一个选择器,在本例中,这可能对OP有好处,尽管我真的无法理解他们的代码。我现在尝试了一下,但似乎不起作用,甚至dajax也停止了工作。使用rebindsuff
而不是'rebindsuff'
,测试againI真的不知道如何感谢你。我就是不知道。非常感谢你的帮助。