I am new to programming and javascript.
What I want to do : Javascript function running on pageload, in this case showVideo(). I want to run this function for a say 10 seconds and then move to the next function.
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) } I tried :
setTimeout(function(){showVideo2},40000) but it did not work. Any ideas?
showVideo2without()is just a function reference, not an executing call to the function. You either wantsetTimeout(showVideo2, 40000)which passes the function reference tosetTimeoutfor calling later, orsetTimeout(function(){ showVideo2() }, 40000)which passes the anonymous function by reference tosetTimeoutand when that anon func is executed it will in turn executeshowVideo2.