cheap jQuery fix for the firefox video loop problem
People who know me know how much I hate flash, therefore when I heard about html5 video and audio I did a happy dance. Recently I had the opportunity to use the video tag in one of my projects and my excitement got a little tempered when I learned that the loop attribute doesn’t work in Firefox. My main browser of choice is safari, too bad not many of my customers visitors share this opinion, so a jQuery fix was needed. It’s far from perfect and it doesn’t work flawless, but it get’s the job done. The only quirk is the little delay to restart the video on end.
$('video[loop="loop"]').bind('ended', function(){this.play();})
Comments (6)
loopis a boolean attribute, so you should change the selector to justvideo[loop].You don’t need jQuery, by the way :)
document.querySelectorAll('video[loop]').onended = function() {this.play();
};
I know, it’s a bit of overhead but since I was already using jQuery in the project…
Nice and simple. Thanks
I’m sorry I have almost no JS knowledge at all but needs this for work to fix this looping issue.
How do I use this code, where do i put it and do I need to include anything else?
Thank you.
When using jQuery you can put this in your jQuery(document).ready(function(){ // code here });
Simple code, but it works fine…Thanks.