开发者

Use jQuery to control video tag

开发者 https://www.devze.com 2023-01-22 22:57 出处:网络
So, I want to use a jQuery function to collect a URL from a link\'s REL, and pass it to aelement. Collecting the REL and sending it to theis no problem... but what\'s required to trigger the element\

So, I want to use a jQuery function to collect a URL from a link's REL, and pass it to a element.

Collecting the REL and sending it to the is no problem... but what's required to trigger the element's load and play functions, from jQuery?

Here's what I have so far:

$(function(){   
    $('a.componentLink').click(function() {
        event.preventDefault();
        var vidURL = $(this).attr('rel');
        $('#myVideo >开发者_高级运维; source').attr('src', vidURL);
        $('#myVideo').load();
        $('#myVideo').play();
    })
});

ATM, it doesn't play... I assume jQuery doesn't natively have access to the play function... but there must be a way around that.


You need to call .play() on the element itself, not on the jQuery selection. Do the following:

$(function(){   
    $('a.componentLink').click(function() {
        event.preventDefault();
        var vidURL = $(this).attr('rel');
        $('#myVideo').attr('src', vidURL);
        var video = $('#myVideo').get(0);
        video.load();
        video.play();
    })
});
0

精彩评论

暂无评论...
验证码 换一张
取 消