Javascript 在单击时隐藏的视频上创建div和图像覆盖
我需要这样的东西。 但是第二个Javascript 在单击时隐藏的视频上创建div和图像覆盖,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我需要这样的东西。 但是第二个div#hide应该位于屏幕的左上角,并留有一些边距。我想不出来。此外,一旦点击youtube上的图像,视频会缩小到默认大小。有没有办法不用 html 作用 $('#hide').click(function() { video = '<iframe src="' + $(this).attr('data-video') + '"></iframe>'; $(this).replaceWith(video); $('#
div
#hide
应该位于屏幕的左上角,并留有一些边距。我想不出来。此外,一旦点击youtube上的图像,视频会缩小到默认大小。有没有办法不用
html
作用
$('#hide').click(function() {
video = '<iframe src="' + $(this).attr('data-video') + '"></iframe>';
$(this).replaceWith(video);
$('#hide1').hide();
});
$('#隐藏')。单击(函数(){
视频='';
$(此).替换为(视频);
$('#hide1').hide();
});
关于尺寸问题,我建议:
$('img').click(function () {
// creating an <iframe> element:
var video = $('<iframe />', {
// setting its properties,
// this.dataset.video returns the
// value of the 'data-video' attribute:
'src': this.dataset.video,
// retrieves the height/width:
'height': this.clientHeight,
'width': this.clientWidth
});
$(this).replaceWith(video);
});
参考资料:
- CSS:
位置
- JavaScript:
- jQuery:
div
#hide应该位于屏幕的左上角,并留有一些空白。”-确切的位置是哪里?有多少利润?屏幕的左上角,或.vid
元素的左上角?视频=“”代码>将解决调整大小的问题problem@DavidThomas像这样的@Markai尝试过这样做。这对我不起作用。如果小提琴对你有用,请你编辑一下好吗?谢谢。@turtle哦,没有iframe,对不起,我不认识,非常感谢。已经做了好几个小时了。只有一个问题,有没有办法消除图片顶部和底部的黑色空间;但是这个问题(以及许多类似的问题)已经在网站的其他地方得到了回答;搜索(不可否认,通过谷歌或你选择的任何其他搜索引擎,而不是SO的搜索)应该会产生有用的信息。
$('#hide').click(function() {
video = '<iframe src="' + $(this).attr('data-video') + '"></iframe>';
$(this).replaceWith(video);
$('#hide1').hide();
});
$('img').click(function () {
// creating an <iframe> element:
var video = $('<iframe />', {
// setting its properties,
// this.dataset.video returns the
// value of the 'data-video' attribute:
'src': this.dataset.video,
// retrieves the height/width:
'height': this.clientHeight,
'width': this.clientWidth
});
$(this).replaceWith(video);
});
.vid {
/* other (unchanged) styles omitted for brevity */
position: relative;
}
.vid div {
/* other (unchanged) styles removed for brevity */
position: absolute;
top: 10%;
left: 10%;
}
/* some minor changes follow,
just for tidying up/aesthetics;
but irrelevant to the 'positioning'
aspect */