gpt4 book ai didi

javascript - 让 jquery 插件在 Ajax 调用后工作

转载 作者:行者123 更新时间:2023-12-01 01:50:34 24 4
gpt4 key购买 nike

这将是一篇很长的文章,但我真的已经受够了尝试解决这个问题。我真的在寻求一些帮助来解决我的案子。

第一:

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
});
});

这里的问题是在下一页的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 调用之后如何才能使其正常工作,该调用应该在加载时淡出,然后在我将鼠标悬停在其上时淡出。

第二:

我有一个可以在图像上向上滑动的小 slider ,slider.js:

$(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 个插件工作即可。

Ajax :

@dajaxice_register
def gallerypages(request, p):

try:
page = int(p)
except:
page = 1

items = gallerylist(page)
html = render_to_string('gallery_content.html',
{'items': items,},
context_instance = RequestContext(request))

dajax = Dajax()
dajax.assign('#gallery-content', 'innerHTML', html)
return dajax.json()

编辑2:

<a href="#" onclick="Dajaxice.gallery.gallerypages(Dajax.process, {'p': {{ items.previous_page_number }},})" class="btn_prev"><b>&lt;</b></a>

$(document).on("keydown", "#pagenumber", function(e)
if ( e.which === 13 ) {
Dajaxice.gallery.gallerypages(Dajax.process, {'p': this.value});
}});

最佳答案

我不确定,但测试一下这个东西:

通过 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>&lt;</b></a>

关于javascript - 让 jquery 插件在 Ajax 调用后工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11786717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com