[英]Loop through a jQuery .post function multiple times
所以我在wordpress網站上使用jsplayer HTML5播放器,以及一些自定義腳本來加載下一篇文章,並在視頻播放完畢后替換舊內容:
$(document).ready(function(){
$(".video-js").bind('ended', function(){
var sStr = "<?php echo get_permalink(get_adjacent_post(true,'',true)); ?>";
var adj_numb = "<?php
$adj = get_adjacent_post(true,'',true);
$numb = $adj->ID;
echo $numb
?>";
var cur_numb = "<?php echo $post->ID; ?>";
$.post(sStr, function(data) {
var content = $( data ).find( '#post-' + adj_numb);
$( "#post-" + cur_numb ).html( content );
var vid = VideoJS.setup( "vid" );
vid.play();
});
});
});
對於一部影片,效果很好。 它會在下一個視頻中加載並播放,但是在第二個視頻播放之后,它會停止播放。 我認為這意味着我必須對所有變量進行“重置”,然后從腳本的開頭重新開始,並且由於$(document).ready(function(),它沒有執行此操作,因為它已經全部加載到了這點。
是否有一種標准方法可以再次遍歷此腳本,並在運行一次后重新設置所有變量?
謝謝!
編輯:渲染的JS:
$(document).ready(function(){
$(".video-js").live('ended', function(){
var sStr = "http://www.theloniousfilms.com/zachmath/volkswagon/";
var adj_numb = "94";
var cur_numb = "96";
$.post(sStr, function(data) {
var content = $( data ).find( '#post-' + adj_numb);
$( "#post-" + cur_numb ).html( content );
var vid = VideoJS.setup( "vid" );
vid.play();
});
});
});
HTML:
<div class="post-96 post type-post status-publish format-standard hentry category-zachmath" id="post-96">
<h2 id="director">Zach Math</h2>
<h2 id="post_title">Orkin -
<span id="post_name">
"Hot Tub"
</span>
<span id="home"><a href="http://www.theloniousfilms.com/">HOME</a></span>
<div class="entry">
<div class="video-js-box">
<!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><br />
<video id="vid" class="video-js" width="640" height="360" preload autoplay poster="http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg"><br />
<source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /><br />
<source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.ogv" type='video/ogg; codecs="theora, vorbis"' /><br />
<!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><br />
<object class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash"<br />
data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"><param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /><param name="allowfullscreen" value="true" /><param name="flashvars" value='config={"playlist":["http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg", {"url": "http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v","autoPlay":true,"autoBuffering":true}]}' /><!-- Image Fallback. Typically the same as the poster image. --><br />
</object><br />
</video>
</div>
看起來HTML正在被重寫
$( "#post-" + cur_numb ).html( content );
更改
$(".video-js").bind('ended', function(){
至
$(".video-js").live('ended', function(){
應該照顧它。
另外,改變
$( "#post-" + cur_numb ).html( content );
與
$( "#post-" + cur_numb ).replaceWith( content );
我最后只是將所有發布網址拉到一個數組中,然后遍歷它們中的每個,一旦上一個視頻播放完畢,就移到數組中的下一個項目。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.