[英]Alternate <div> content at every 10 seconds is not working
Functionality: 功能:
I have 2 diff <div>
content at the same page, hence, Content A is shown before Content B is shown and the loop will re-iterate again. 我在同一页面上有2个diff
<div>
内容,因此,在显示内容B之前先显示内容A,然后循环将再次重复。 Therefore, the process is as described below: 因此,该过程如下所述:
Content A (shown for 10seconds)-> Content B (shown for 10seconds) -> Content A (shown for 10 seconds) -> Content B (shown for 10 seconds) 内容A(显示10秒)->内容B(显示10秒)->内容A(显示10秒)->内容B(显示10秒)
Hence, the display of the content will be shown in an re-iteration for infinite loops. 因此,内容的显示将以无限循环重复显示。
Content A -> a list of jplayer content Content B -> a static <div>
content 内容A-> jplayer内容列表内容B->静态
<div>
内容
What has been done: 已经做了什么:
I have set the following: 我设置了以下内容:
Created a <div>
for Content A: 为内容A创建了
<div>
:
<div id="M_Start" align= "center" style ="position:absolute; width:1080px; height:1920px; background-repeat: no-repeat; z-index=1; top:0px; left:0px;"> <!--Video Div for Content A--> <div id="Start_Video" style="position:absolute;"></div> </div>
Created a <div>
for Content B: 为内容B创建了
<div>
:
<div id="I_Page" align= "center" style ="position:absolute; width:1080px; height:1920px; background-repeat: no-repeat; display: none; z-index=3; top:0px; left:0px;"> <table cellspacing="0" cellpadding="0" width="1080"> <tr> <td width="1080" align="center"> <div id="i_page_content" style="position:absolute; z-index:2; top:1020px; left:22px; overflow-y:scroll; overflow-x:hidden; height:820px; width:1050px;"></div> </td> </tr> </table> </div>
Secondly, I have done setTimeInterval for both Content such that after 10 seconds, the contents will switch. 其次,我为两个Content都完成了setTimeInterval,以便在10秒后,内容将切换。 My code as shown:
我的代码如下所示:
var videoList = ["lib/video/MainBackground.mp4", "lib/video/I.mp4"]; var videoIndex = 0; setInterval(function() { $("#M_Video").jPlayer({ ready: function() { console.log("currentPlaying " + videoList[videoIndex]); $("#M_Video").jPlayer("setMedia", { m4v: videoList[videoIndex] }).jPlayer("play"); }, ended: function() { videoIndex++; console.log("NewCurrent:" + videoIndex); console.log("current :" + videoList[videoIndex]); if (videoIndex >= videoList.length) { console.log("Next" + videoIndex); videoIndex = 0; //ContentB to fadeIn $('#IPage').fadeIn({ duration: slideDuration, queue: false }); } $("#M_Video").jPlayer("setMedia", { m4v: videoList[videoIndex] }).jPlayer("play"); }, swfPath: "javascript", muted: true, loop: true, supplied: "webmv, ogv, m4v", size: { width: 1080, height: 1920 } }); $("#M_Video").show(); }, 10000);
<!--Content A --> <div id="M_Start" align="center" style="position:absolute; width:1080px; height:1920px; background-repeat: no-repeat; z-index=1; top:0px; left:0px;"> <!--Video Div--> <div id="M_Video" style="position:absolute;"></div> <button class="MilleniaStart" onclick="Start()"></button> </div> <!--Content B--> <div id="IPage" align="center" style="position:absolute; width:1080px; height:1920px; background-repeat: no-repeat; display: none; z-index=3; top:0px; left:0px;"> <table cellspacing="0" cellpadding="0" width="1080"> <tr> <td width="1080" align="center"> <div id="i_page_content" style="position:absolute; z-index:2; top:1020px; left:22px; overflow-y:scroll; overflow-x:hidden; height:820px; width:1050px;"></div> </td> </tr> </table> </div>
Issue: 问题:
After the contents have been switched after 10secs, the switch of content stops and it does not re-iterate the switching of the content anymore. 在10秒钟后切换内容后,内容切换将停止,并且不再重复进行内容切换。 Meaning: after Content A has switched to Content B, it stops, when the correct behaviour should be Content A switched to Content B and then switches back to Content A before switching to Content B and to Content A, the re-iteration should never stops.
含义:在内容A切换到内容B后,它停止了,当正确的行为应该是内容A切换到内容B,然后又切换回内容A,再切换到内容B和内容A时,重复播放就永远不会停止。
Hence, I do require some help. 因此,我确实需要一些帮助。 Please help.
请帮忙。 I do not know how to proceed or what has gone wrong.
我不知道如何进行或出了什么问题。
Thank you. 谢谢。
Try this: 尝试这个:
/*** javascript/jQuery: ***/ var videoList = ["http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", "http://www.html5videoplayer.net/videos/toystory.mp4"]; var videoIndex = 0; console.log("current: " + videoList[videoIndex]); $("#M_Video").jPlayer({ ready: function() { $("#M_Video").jPlayer("setMedia", { m4v: videoList[videoIndex] }).jPlayer("play"); }, swfPath: "javascript", muted: true, loop: true, supplied: "webmv, ogv, m4v", size: { width: 500, height: 400 } }); setTimeout(swapVideo, 10000); function swapVideo(){ videoIndex++; if (videoIndex >= videoList.length) { //console.log("Next < " + videoIndex); videoIndex = 0; } //console.log("NewCurrent:" + videoIndex); $("#M_Video").jPlayer("destroy"); $("#M_Video").jPlayer({ ready: function() { console.log("current: " + videoList[videoIndex]); $("#M_Video").jPlayer("setMedia", { m4v: videoList[videoIndex] }).jPlayer("play"); }, swfPath: "javascript", muted: true, loop: true, supplied: "webmv, ogv, m4v", size: { width: 500, height: 400 } }); setTimeout(swapVideo, 10000); }
/*** CSS: ***/ .divs{position:absolute;top:0;left:0;width:500px;height:400px;background-repeat:no-repeat;} #M_Start{z-index=1;} #M_Video{position:absolute;} #IPage{z-index=3;display:none;} #i_page_content{height:400px;width:500px;overflow-y:scroll;overflow-x:hidden;z-index:2;}
<!-- *** HTML: *** --> <link href="https://cdnjs.cloudflare.com/ajax/libs/jplayer/2.9.2/skin/blue.monday/css/jplayer.blue.monday.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jplayer/2.9.2/jplayer/jquery.jplayer.min.js"></script> <!--Content A --> <div id="M_Start" class="divs" align="center"> <div id="M_Video"></div> <button class="MilleniaStart" onclick="Start()"></button> </div> <!--Content B--> <div id="IPage" class="divs" align="center"> <table cellspacing="0" cellpadding="0" width="500"> <tr><td width="500" align="center"><div id="i_page_content"></div></td></tr> </table> </div>
Reference (please upvote): 参考(请投票):
jQuery jPlayer change media not working jQuery jPlayer更改媒体不起作用
Well, if you are looking for just switching the div's after every 10 secs with infinite loop, check this fiddler. 好吧,如果您希望每10秒无限循环切换一次div,请检查此提琴手。
https://jsfiddle.net/nalinkaggarwal/vj01xezm/ ` https: // jsfiddle.net/ nalinkaggarwal/ vj01xezm/ `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.