Ajax回调后的JQuery slimbox重新绑定 [英] JQuery slimbox rebind after ajax callback

查看:138
本文介绍了Ajax回调后的JQuery slimbox重新绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

装载Ajax内容后,我无法重新绑定slimbox2。我意识到我需要重新绑定Ajax的负载功能,但我不知道该怎么做。我使用这个code产生的外部内容。

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

这篇关于Ajax回调后的JQuery slimbox重新绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆