我正在为videojs
编写一个新插件。我对if语句有疑问:
if (getCTime == 5 && c == true) {
this.removeChild(createDiv);
}
5秒后无法删除div元素。我该怎么办?
代码:
(function() {
'use strict';
//Create Component
videojs.containerDiv = videojs.Component.extend({
init: function(player, options) {
videojs.Component.call(this, player, options);
}
});
// get current time and create new element
videojs.containerDiv.prototype.timeUpdate = function(player, options) {
var c = false;
this.player_.on('timeupdate', function() {
var getCTime = Math.floor(this.cache_.currentTime);
var createDiv = new videojs.containerDiv(this, options);
// In 2 seconds are show ads
if (getCTime == 2 && c == false) {
// Create new div for ads
this.addChild(createDiv);
//Close ads
this.one(createDiv.newDivClose_,'click', function() {
this.removeChild(createDiv);
});
c = true;
}
if (getCTime == 5 && c == true) {
this.removeChild(createDiv);
}
});
}
videojs.containerDiv.prototype.createEl = function() {
var newDiv = videojs.createEl('div', {
className: 'vjs-new-div'
});
var newDivInside = videojs.createEl('div', {
className: 'vjs-new-div-inside'
});
var newDivClose = videojs.createEl('div', {
className: 'vjs-btn-close',
innerHTML: 'x'
});
this.newDivClose_ = newDivClose;
newDiv.appendChild(this.newDivClose_);
this.contentEl_ = newDivInside;
this.contentEl_.innerHTML = this.innerHTML();
newDiv.appendChild(this.contentEl_);
return newDiv;
};
videojs.containerDiv.prototype.innerHTML = function() {
this.textAds = "Hello World";
return this.textAds;
}
var pluginFn = function(options) {
var myComponent = new videojs.containerDiv(this, options);
myComponent.timeUpdate(this, options);
};
videojs.plugin( 'myPlugin', pluginFn );
})();