1
我创建加载通过AJAX外部内容的页面。猫头鹰旋转木马,阿贾克斯负载
$(".link").click(function(e) {
e.preventDefault()
$("#ajax-container")load("external-file.php");
});
这工作,但在外部文件的内容包含猫头鹰旋转木马,它会出现在加载的HTML,但不(再)初始化。
根据猫头鹰文档和SIMIALR帖子(How to reinitialize Owl Carousel after ajax call),我需要销毁并重新启动传送带。 当连接到独立点击时,此功能完美无缺。
$(".button").click(function(e){
e.preventDefault()
$("#carousel").data('owlCarousel').destroy();
$("#carousel").owlCarousel();
});
但我需要这个发生没有额外的点击ajax文件加载后。我已经尝试了所有以下方法,但没有运气。
// adding to original
$(".link").click(function(e){
e.preventDefault()
$("#ajax-container")load("external-file.php");
$("#carousel").data('owlCarousel').destroy();
$("#carousel").owlCarousel();
});
// in addition to original
$(".link-second-classname").click(function(e) {
e.preventDefault()
$("#carousel").data('owlCarousel').destroy();
$("#carousel").owlCarousel();
});
// ajaxComplete
$(document).ajaxComplete(function(e){
e.preventDefault()
$("#carousel").data('owlCarousel').destroy();
$("#carousel").owlCarousel();
});
// ajaxSuccess
$(document).ajaxSuccess(function(e){
e.preventDefault()
$("#carousel").data('owlCarousel').destroy();
$("#carousel").owlCarousel();
});
任何帮助或建议将大规模赞赏。
谢谢。
你是一个明星。谢谢。 – fluffyside