我不明白为什么会这样。我有一个刷卡器嵌套在另一个刷卡器中(一个用于垂直滚动,另一个用于水平滚动。让我发疯的是嵌套刷卡器在我需要销毁它时没有定义。这就是我正在做的事情:
function embedSwiper(){
var embeddedEcosystem = new Swiper('.swiper-nested', {
//Styling set in bootstrap.min.css for pagination
mode: 'vertical',
pagination: '.pagination-nested',
paginationClickable: true,
simulateTouch : true,
});
embeddedEcosystem.swipeTo(0, 500, false);
return embeddedEcosystem;
}
这将创建 swiper,并将其返回给此函数:
function reInitEmbedded(){
setTimeout(function(){
embed = embedSwiper();
$(".swiper-nested").css({"height" : "0px"});
$(".swiper-nested").css({"height" : $(".internal-relations").height()});
useLocalImg();
embed.reInit();
//Set the slide height properly since it never works as intended
return embed;
}, 600);
}
我需要在此处设置高度,否则幻灯片未正确安装(是的,我尝试过计算高度,但由于我使用的是工作灯,因此在移动设备上出现了问题)
现在,这就是事情变得古怪的地方。我正在 chrome 中对此进行测试(抱歉,目前我无法为您提供链接)。
//Resize cards
swiper = reinitSwiper();
innerSwiper = reInitEmbedded();
//Show info
detailsTransition();
//Hides the overlay, and empties the panels to be filled next time
//Bound calls for use when needed
$(".back-button.btn.btn-primary.pull-left").on('click', function(){
goBack(lookUpName);
innerSwiper.destroy();
swiper.destroy();
});
如您所见,我有swiper
变量,它可以正常工作并且可以正常销毁,并且我有 innerSwiper。其余的无关紧要,因为它在此之前就已经工作了。让我发疯的是,它innerSwiper
不断出现undefined
,但这不应该是因为我已经在 chrome 的调试器中跟踪了堆栈调用,并且returns
所有这些都具有内部 swiper 的 swiper 变量。所以我的问题是:我做错了什么,我一直不确定?