我有一个带有响应式视频的滑块,可以全屏显示。在全屏模式下单击海报图像时,我想获取.clientWidth
图像以设置加载视频 iframe 的 div (.sp-layer)。
事件fullscreenchange
似乎工作正常,但是每当我单击.on('click')
事件的链接时,fullScreenMode 是未定义的?
this.fullScreenMode = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
console.log("initial fullScreenMode: " + this.fullScreenMode);
$(document).on('mozfullscreenchange webkitfullscreenchange fullscreenchange', function() {
console.log('fullscreenchange Event fired');
this.fullScreenMode = !this.fullScreenMode;
console.log('fullScreenMode: ' + this.fullScreenMode);
if (!this.fullScreenMode) {
console.log('we are not in fullscreen, do stuff');
$('.sp-layer').css('width', '100%');
}
});
$('a.sp-video').on('click', function() {
console.log('clicked on link');
console.log('fullScreenMode: ' + this.fullScreenMode);
if (this.fullScreenMode) {
console.log('we are fullscreen, do stuff');
var cW = $(this).children('img')[0].clientWidth;
console.log('clientWidth of image: ' + cW);
$(this).parent('.sp-layer').css('width', cW);
}
});