JQuery autoplay video on click show

限于喜欢 提交于 2019-12-08 14:52:14

问题


I'm using JQuery on a navigational panel that operates as click to show/hide. On the "About" panel is small html5 video that I would like to auto start on click-show and stop video on click-hide. The id for the "About" panel is:

<div class="panel2">

Sample code for how the panels function:

$(document).ready(function(){
$(".triggerso").click(function(){
    $(this).hide();
    $(".panelso").show("fast");
    $('.panelso').click(function(){ 
    $(this).hide();
    $('.triggerso').show("fast"); });
    $(".panel").hide("slow");
    $(".panel1").hide("slow");
    $(".panel2").hide("slow");
    $(".panel3").hide("slow");
    return false;
});
});

Thanks you so much for your help.

Andrea


回答1:


See this:
http://www.w3.org/TR/html5/video.html#video

and the controls attribute:
http://www.w3.org/TR/html5/video.html#attr-media-controls

probably the media methods ".play()" and ".pause()" will help you

Something like this:

var video = $("#myvideo")[0]; // id or class of your <video> tag
if (video.paused) {
    video.play();
}    

the "[0]" is to get the html element instead of a jQuery object.



来源:https://stackoverflow.com/questions/6574323/jquery-autoplay-video-on-click-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!