Martin
Martin

Reputation: 445

jquery script for video start after page is loaded

i got a question if in jquery exists some event which allow me to play video instantly after my website is loaded. For now i using mousemove event, which works fine for now, but if i want add another layer on my website over my video content, it should not work.

$(function(){ 
var video = document.querySelector('#video1'); 
if(video){
video.addEventListener('mousemove',function(){ video.play(); },false)
}; 
}); 

Upvotes: 0

Views: 2903

Answers (2)

putvande
putvande

Reputation: 15213

Assuming you are using the <video> element, you can just add the autoplay attribute:

<video autoplay>
    <source src=""/>
</video>

Upvotes: 0

ckuijjer
ckuijjer

Reputation: 13814

Can't you simply start the video when jQuery document ready function is fired?

$(function(){ 
    var video = document.querySelector('#video1');
    video.play();
});

At least that seems to work in this small Codepen I created from the W3Schools HTML5 video example.

Upvotes: 1

Related Questions