[英]jquery video reset on dialog close
I have 2 inline videos and popup on the same page with a video embedded. 我在同一页面上有2个嵌入式视频和弹出窗口,其中嵌入了一个视频。 Whenever I open the popup and play the video and then I close the dialog box the video should be reset instead of staying paused in the same position where I closed it when I open the dialog again.
每当我打开弹出窗口并播放视频,然后关闭对话框时,都应该重设视频,而不是在再次打开对话框时保持在关闭它的位置。
var activeDialog = com.gsk.mt.getActiveDialog();// gets active dialog id
if (activeDialog !== null && !activeDialog.hasClass("quickLinkDialog") && activeDialog.hasClass("videoDialog")) {
$('video').each(function() {
$(this).get(0).pause();
$(this).get(0).currentTime = 0;
});
}
For this code, all the videos are being reset as I'm using each function. 对于此代码,当我使用每个功能时,所有视频都将被重置。 How can reset only the video in the popup?
如何仅重置弹出窗口中的视频? Can anyone help me with this?
谁能帮我这个?
You need to traverse the DOM to find the video
elements within the dialog which was closed. 您需要遍历DOM,以在对话框中找到已关闭的
video
元素。 Assuming that activeDialog
is a jQuery object, which it would appear to be given your use of hasClass()
, then you can simply use find()
, like this: 假设
activeDialog
是一个jQuery对象,似乎可以使用hasClass()
,则只需使用find()
,如下所示:
var activeDialog = com.gsk.mt.getActiveDialog(); if (activeDialog !== null && !activeDialog.hasClass("quickLinkDialog") && activeDialog.hasClass("videoDialog")) {
activeDialog.find('video').each(function() {
this.pause();
this.currentTime = 0;
});
}
Also note the use of this
over $(this).get(0)
to change the video's properties. 还要注意在
$(this).get(0)
上使用this
来更改视频的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.