简体   繁体   English

在“点击”时重置addClass函数

[英]reset addClass function on 'click'

so, I have a function that makes an image invisible, and at the same time starts playing a video (1 out of 6) underneath it. 因此,我有一个使图像不可见的功能,并同时开始在其下方播放视频(6个中的1个)。 It works great, the div fades out, and it plays. 它的效果很好,div逐渐消失,然后开始播放。 However, it only works the first time. 但是,它只能在第一次使用。

There are six thumbs(all an item in a list), and they each play one of the videos, right? 有六个拇指(列表中的所有项),每个拇指都播放其中一个视频,对吗? So, each time a thumb is pressed, I need the image to comeback(quickly) and then fade out slowly like it does. 因此,每次按下拇指时,我都需要图像(迅速)恢复,然后像它一样慢慢淡出。 So, a mini reset of sorts on each click. 因此,每次点击都会进行少量的重置。

the code is 该代码是

 $(document).ready(function () { $('li, .thumbs').on('click', function () { var numb = $(this).index(), videos = [ 'images/talking1.m4v', 'images/talking2.m4v', 'images/talking1.m4v', 'images/talking2.m4v', 'images/talking1.m4v', 'images/talking2.m4v' ], myVideo = document.getElementById('myVid'); myVideo.src = videos[numb]; myVideo.load(); $('#MyT').addClass('clear'); myVideo.play(); }); }); 

i tried shuffling things around, and no dice. 我试图改组周围的东西,没有骰子。 And, yes, it is supposed to start fading once the video has finished loading. 而且,是的,一旦视频加载完成,它应该开始褪色。 This is for iPad and I haven't found a better way around the flicker you get when a video loads. 这是针对iPad的,我还没有找到解决视频加载时闪烁的更好方法。

Edit: okay, trying to explain this best way I can... the page loads, and you have the image on top. 编辑:好的,尝试解释这种最佳方式我可以...页面加载完毕,并且您的图像位于顶部。 There are six thumbnails, and one is clicked. 有六个缩略图,然后单击一个。 The image fades out while the video loads(this doesn't have to be synced, so long as the video finishes loading first), then it plays. 加载视频时,图像会淡出(不必同步,只要视频先完成加载即可),然后播放。 If a some point, another of the thumbs is pressed, the image pops back up and fades, to cover while the video loads. 如果在某个位置按下了另一个拇指,则图像会弹出并逐渐消失,以在视频加载时覆盖。 Basically, the condition of the first click repeats on each click. 基本上,第一次点击的条件会在每次点击时重复。

Try the following for checking when the video has ended: 请尝试以下方法检查视频何时结束:

$('#my_video_id').bind("ended", function(){ 
      alert('Video Ended'); 
      $('#MyT').removeClass('clear');
    });

Taken from http://help.videojs.com/discussions/questions/40-jquery-and-event-listeners 取自http://help.videojs.com/discussions/questions/40-jquery-and-event-listeners

Seems to have worked for them, so let me know if you have similar results. 似乎为他们工作了,所以如果您有相似的结果,请告诉我。

Edit 编辑

So when your thumbnail is clicked you should first check to see if a video is already playing as discussed in the link in the comments section. 因此,单击缩略图时,您应该首先查看视频是否已经在播放,如评论部分中的链接所述。 If a video is playing, stop that video and add the class 'clear' back the that video. 如果正在播放视频,请停止播放该视频,然后将“清除”类添加回该视频。 Then you can go ahead and fade the 2nd video in. I obviously can't write all that for you because I don't know all the conditions, constraints and the html code you have, but the basic outline is there. 然后,您可以继续播放第二个视频,淡入淡出。我显然不能为您编写所有视频,因为我不知道所有条件,约束和html代码,但是这里有基本轮廓。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM