Javascript 引导--在滑动到下一个旋转木马之前,等待视频完成
我希望我的旋转木马在转到下一张幻灯片之前等待视频完成。这是我的代码,我根据数据库中媒体文件的数量循环它Javascript 引导--在滑动到下一个旋转木马之前,等待视频完成,javascript,jquery,html,twitter-bootstrap,carousel,Javascript,Jquery,Html,Twitter Bootstrap,Carousel,我希望我的旋转木马在转到下一张幻灯片之前等待视频完成。这是我的代码,我根据数据库中媒体文件的数量循环它 <div id="mediaCarousel" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <!-- container dimensions should be max = w1338xh691
<div id="mediaCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<!-- container dimensions should be max = w1338xh691 -->
<!-- if there's no media -->
<?php if(!$media): ?>
<!-- callback here, in case there's no media in the database. -->
<div class="item">
<img src="<?php echo base_url()?>assets/water.jpg"/>
</div>
<!-- else -->
<?php else: ?>
<!-- call carousel -->
<!-- foreach media as _media -->
<?php foreach($media as $_media): ?>
<!-- validate if media type is video -->
<?php if($_media->media_type == 0): ?>
<!-- call video elements -->
<div class="item <?php echo $_media->id == 1 ? 'active' : '' ?>">
<video class="d-block w-100" src="<?php echo $_media->file_url; ?>" muted autoplay="autoplay" preload="auto" id="video"/>
</div>
<!-- validate if media type is image -->
<?php elseif($_media->media_type == 1): ?>
<!-- call image elements -->
<div class="item">
<img class="d-block w-100" src="<?php echo $_media->file_url; ?>"/>
</div>
<!-- else, media is considered "other media" -->
<?php else: ?>
<!-- just call a div -->
<div class="item">
</div>
<!-- endif -->
<?php endif; ?>
<!-- endforeach -->
<?php endforeach; ?>
<!-- endif -->
<?php endif; ?>
</div>
</div>
资产/水。jpg/>
document.getElementById将只返回找到的第一个元素
尝试使用以下代码查找包含所有视频元素的处理程序
<script type="text/javascript">
$("#mediaCarousel").carousel({ interval: false}); // this prevents the auto-loop
var videos = document.querySelectorAll("video.d-block");
videos.forEach(function(e) {
e.addEventListener('ended', myHandler, false);
});
function myHandler(e) {
$("#mediaCarousel").carousel('next');
}
</script>
$(“#mediaCarousel”).carousel({interval:false});//这可以防止自动循环
var videos=document.queryselectoral(“video.d-block”);
视频。forEach(功能(e){
e、 addEventListener('ended',myHandler,false);
});
函数myHandler(e){
$(“#mediaCarousel”).carousel('next');
}
document.getElementById将只返回找到的第一个元素
尝试使用以下代码查找包含所有视频元素的处理程序
<script type="text/javascript">
$("#mediaCarousel").carousel({ interval: false}); // this prevents the auto-loop
var videos = document.querySelectorAll("video.d-block");
videos.forEach(function(e) {
e.addEventListener('ended', myHandler, false);
});
function myHandler(e) {
$("#mediaCarousel").carousel('next');
}
</script>
$(“#mediaCarousel”).carousel({interval:false});//这可以防止自动循环
var videos=document.queryselectoral(“video.d-block”);
视频。forEach(功能(e){
e、 addEventListener('ended',myHandler,false);
});
函数myHandler(e){
$(“#mediaCarousel”).carousel('next');
}
停止此操作是因为javascript只获取第一个ID,您可以尝试定义一个动态ID,例如#mediaCarousel-vid1#mediaCarousel-2为了在javascript中创建要恢复的动态ID,我解决了这个问题,一旦我解决了这个问题,给您一个类,以防不清楚,一个ID用于标识元素,如中所示,您不应该保存具有相同id的多个元素。由于javascript只获取第一个id,因此可以尝试定义一个动态id,例如#mediaCarousel-vid1#mediaCarousel-2。要在javascript中创建要恢复的动态id,我在解决了这个问题后遇到了这个问题。如果不清楚,可以使用一个id来标识元素如中所示,您不应该有多个具有相同id的元素。在将上一个重置为开始时,如何修改此选项以自动播放下一个视频?在将上一个重置为开始时,如何修改此选项以自动播放下一个视频?