[英]In Jquery bx slider plugin how to find the current slider is image or video
How to find the current slider is an image or a video in bx slider.如何找到当前滑块是 bx 滑块中的图像或视频。
If it is a video then the video has to reload if it is an image then do not reload.如果是视频,则视频必须重新加载,如果是图像,则不要重新加载。 But I am using that the image and video both are reloaded when I go to the next slider.但是我使用的是当我转到下一个滑块时重新加载图像和视频。
javascript: javascript:
$(document).ready(function(){
$(".bxslider").bxSlider({
onSlideNext: function(){
var iframe = $("#frameid").attr('src');
$("#frameid").attr('src', iframe);
}
});
});
Use $(ELE).prop('tagName')
to get the element' tagName.使用$(ELE).prop('tagName')
获取元素的 tagName。 <video>
has tagName VIDEO
while <img>
has tagName IMG
. <video>
有 tagName VIDEO
而<img>
有 tagName IMG
。 So you can then do different actions base on that.因此,您可以在此基础上执行不同的操作。
Or use .is('video')
to check if target element is video, as you only want to reload video
.或者使用.is('video')
来检查目标元素是否是视频,因为您只想重新加载video
。
So you can write as :所以你可以写成:
$(document).ready(function(){
$(".bxslider").bxSlider({
onSlideNext: function() {
var $target = $("#frameid");
// Another way
// if ($target.prop('tagName') === 'VIDEO') {
if ($target.is('video')) {
var iframe = $target.attr('src');
$target.attr('src', iframe);
}
}
});
});
PS: If you just want the video
to play from start, I'd suggest use PS:如果您只想从头开始播放video
,我建议您使用
// Set video to start.
video.currentTime = 0;
// If the video has autoplay requirement.
video.play();
As this won't load the video again but just set video to its start point, it won't cost additional traffic to reload the video.由于这不会再次加载视频,而只是将视频设置为其起点,因此重新加载视频不会花费额外的流量。
Snippet:片段:
// TagName console.log($('#im').prop('tagName')); console.log($('#vi').prop('tagName')); // .Is console.log($('#im').is('video')); console.log($('#vi').is('video'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <img id="im"/> <video id="vi"></video>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.