我对编程和javascript很陌生。
我想做的是:运行在页面上的Javascript函数,在本例中是showVideo()。我想运行这个函数10秒,然后移动到下一个函数。
function(){
dostuff();
// dostuff for 10 seconds
// now stop dostuff
// donewstuff();
}
<div class="wrapper">
<div class="screen" id="screen-1" data-video="vid/river.mp4">
<img src="img/bird.jpg" class="big-image" />
</div>
<div class="screen" id="screen-2" data-video="vid/sim.mp4">
<img src="img/spider.jpg" class="big-image" />
</div>
</div>
</div>
<script>
$(function(){
var
BV,
videoPlayer,
BV = new $.BigVideo();
BV.init();
showVideo();
BV.getPlayer();
function showVideo() {
BV.show($('#screen-1').attr('data-video'),{ambient:true});
$('#screen-1').find('.big-image').transit({'opacity':0},500)
setTimeout(function(){showVideo2},40000);
}
function showVideo2() {
BV.show($('#screen-2').attr('data-video'),{ambient:true});
$('#screen-2').find('.big-image').transit({'opacity':0},500)
}我试过:
setTimeout(function(){showVideo2},40000) 但这不起作用。有什么想法吗?
发布于 2014-11-18 19:50:18
你实际上并没有调用这个函数。试试这个:
setTimeout(function() {
showVideo2();
}, 40000);注意()中的showVideo2()。
发布于 2014-11-18 19:49:27
您可以使用setTimeout()
var stopped = false;
setTimeout(function() {
stopped = true;
}, 10000);
while (!stopped) {
// Do stuff here.
}发布于 2014-11-18 19:54:47
我的猜测是,您希望调用showVideo,然后在40多岁之后调用showVideo2。您所拥有的是接近的,但是在超时时没有调用showVideo2。
您有两个解决方案可以解决这个问题:
变化
function showVideo() {
BV.show($('#screen-1').attr('data-video'),{ambient:true});
$('#screen-1').find('.big-image').transit({'opacity':0},500)
setTimeout(function(){showVideo2},40000);
}以下列方式之一:
function showVideo() {
BV.show($('#screen-1').attr('data-video'),{ambient:true});
$('#screen-1').find('.big-image').transit({'opacity':0},500)
setTimeout(showVideo2,40000);
}或者:
function showVideo() {
BV.show($('#screen-1').attr('data-video'),{ambient:true});
$('#screen-1').find('.big-image').transit({'opacity':0},500)
setTimeout(function(){showVideo2(); },40000);
}如果不进行测试,这应该是可行的。如果您有任何问题,请评论。
https://stackoverflow.com/questions/27002712
复制相似问题