jQuery的html5视频canplay事件 [英] html5 video canplay event with jQuery

查看:886
本文介绍了jQuery的html5视频canplay事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态添加的视频元素,以前我有一个内联的oncanplay脚本.

I have a dynamically added video element where I previously had an inline oncanplay script.

<video id="videoCurrent" type="video/mp4" oncanplay="displayVideoChapters(this);" controls>

视频元素已添加到静态div

The video element is added to a static div

<div id="videoDisplay"> </div>

我现在正尝试将canplay事件附加到<head>

I am now trying to attach the canplay event to the video element with jQuery from a scripts file linked in <head>

$(document).ready(function() {
  $("#videoDisplay").on('canplay', 'video#videoCurrent', function() {
    console.log(this);
  });
});

但是,什么也没发生.我尝试过其他活动; loadstartpauseplay具有相同的结果. mouseover是我唯一可以触发console.log(this)的事件. 我不明白什么?

However, nothing happens. I've tried other events; loadstart, pause, play with the same result. mouseover is the only event I can get to trigger the console.log(this). What am I not understanding?

推荐答案

我通过在回调函数中添加canplay事件来解决此问题,该回调函数从缩略图链接获取动态视频播放器.

I solved this by adding the canplay event to the callback function which gets the dynamic video player from thumbnail image links.

$('#staticVideoPlayerContainer').on('click', 'a.videoUrl', function() {
    $.get('url', function(data) { 
        $("#videoDisplay").html(data);                   //Dynamic video player is added
        $("#videoCurrent")[0].oncanplay = function() {   //Event listener attached
            console.log(this);                           //Logs video on canplay
        }
    });
});

这篇关于jQuery的html5视频canplay事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆