问题
I'm using the video.js plugin. I'm using ajax to load in another bunch of videos from another page but I want to call the javascript again to perform the skinning again. Is there a callback function I can use after my ajax has finished loading in the html?
To be specific I'm after the actual function name (if there is one) that video.js has made. ie the javascript which runs to dress up the videos.
回答1:
Ajax has a success call back you may be able to use.
$.ajax({
type: "GET",
url: url,
success: function(data){
//Call back stuff
}
});
There are also, error and other callbacks you can use. You can find information on here.
If you don't have access to the ajax event, you can still bind to the success call back. Here's documentation on how to do it.
回答2:
The best solution I found was here
(function(){
var video = document.querySelector('video');
var onDurationChange = function(){
if(video.readyState){
//to your thing
}
};
video.addEventListener('durationchange', onDurationChange);
onDurationChange();
})();
Trying to do
videojs("myplayer").ready(function() {
console.log(this.duration()); //0
});
wouldn't work.
来源:https://stackoverflow.com/questions/16483808/callback-function-for-video-js