JQuery slimbox重新绑定后的ajax回调 [英] JQuery slimbox rebind after ajax callback
本文介绍了JQuery slimbox重新绑定后的ajax回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在加载ajax内容后重新绑定slimbox2时遇到问题。我意识到我需要重新绑定在ajax负载的功能,但我不知道如何做到这一点。我使用此代码生成外部内容。
I'm having trouble rebinding slimbox2 after ajax content is loaded. I realize I need to rebind the function on the ajax load but I have no idea how to do that. I'm using this code to generate the external content.
$(document).ready(function() {
$('.content_box').hide();
$('.sf-menuUP a').click(function(){
$('.content_box').fadeIn('slow');
});
var hash = window.location.hash.substr(1);
var href = $('.sf-menuUP li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});
$('.sf-menuUP li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').fadeOut('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').fadeIn('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});
// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
jQuery(function($) {
$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
});
});
到我的脚本底部,希望只是重新加载它。但没有运气。我读过livequery可以工作,但我不知道如何/在哪里/该怎么办。
to the bottom of my script hoping that would just reload it. But no luck. I've read livequery could work, but I don't know how/where/what to do with that.
我越来越绝望。请任何人?
I'm getting desperate. Please anyone?
感谢。
推荐答案
liveQuery 。这里是您需要做的:
I took a look at liveQuery for you. Here's what you'd need to do:
$("a[rel^='lightbox']").livequery(function(){
$(this).slimbox({/* Put custom options here */}, null, function(el) {
return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
}), function() {
//remove slimbox? this is called when elements no longer match
}
});
这篇关于JQuery slimbox重新绑定后的ajax回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文