我试图在活动的flickity实例中定位iframe,因为我可能在单个页面上有几个flickity实例(最终目标是刷新幻灯片中曾经查看过的iframe用户选择了另一张幻灯片。)
我让这个用于单个幻灯片放映,但是当我在页面上有多个幻灯片时遇到问题,因为它会刷新之前选择的所有iframe,而不仅仅是活动中的那个iframe幻灯片放映。
下面是我的脚本,其中" .slideshow"是一个flickity实例,我希望能够在页面上有多个。这个问题与定位正确的“以前的视频集会”有关。其父母刚刚解雇了" sett.flickity"事件。有什么想法吗?
$('.slideshow').each(function(index, element) {
// in case the first slide is a video
var previousVideoContainer = $(this).find('.slideshow-cell.is-selected iframe');
$(this).on('settle.flickity', function () {
//reload iframe in previously viewed slide to "stop" the video
$(previousVideoContainer).each(function(ev) {
var video = this;
$($(video),parent.document).attr('src',$($(video),parent.document).attr('data-src'));
});
var videoContainer = $('.carousel-cell.is-selected iframe');
previousVideoContainer = videoContainer;
});
});
答案 0 :(得分:1)
我回答了自己的问题。问题在于我没有将" videoContainer"变量与我使用previousVideoContainer的方式相同。 Flickity工作正常。这是修改后的代码:
$('.slideshow').each(function(index, element) {
// in case the first slide is a video
var previousVideoContainer = $(this).find('.slideshow-cell.is-selected iframe');
$(this).on('settle.flickity', function () {
//reload iframe in previously viewed slide to "stop" the video
$(previousVideoContainer).each(function(ev) {
var video = this;
$($(video),parent.document).attr('src',$($(video),parent.document).attr('data-src'));
});
var videoContainer = $(this).find('.slideshow-cell.is-selected iframe');
previousVideoContainer = videoContainer;
});
});