When someone clicks an image it will darken the screen and the video will play. But it's not working, any help would be appreciated. Thank you. (I'm using bootstrap and fullpage.js)
HTML:
<html>
<body>
<div class="row">
<div class="col-lg-3">
<img "myImg" scr="images/myimage.jpeg" myVideo="https://youtube.com/embed/" width="100%">
</div>
</div>
</body>
</head>
Jquery:
$("#myImg").click(function(){
video = '<iframe src="'+ $(this).attr('myVideo') +'" width="600px" height="auto"></iframe>';
div = document.createElement('div');
div.style.backgroundColor = "rgba(0,0,0,0.9)";
div.style.position = "absolute";
div.style.width = "100vw";
div.style.height = "100vh";
div.style.left = "0";
div.style.top = "0";
div.style.verticalAlign = "middle";
div.html = video;
document.getElementsByTagName('body')[0].appendChild(div);
});
There are a few errors:
1) Your jQuery
click
event is looking for a click on an element with the ID ofmyImage
, but your image has no ID right now. Change<img "myImg" ...
to<img id="myImage" ...
to fix the click event.2) You misspelled
src
(source) asscr
on your<img>
.3) HTML is set on elements using JS with
.innerHTML
, not.html
. Changediv.html = video;
todiv.innerHTML = video;
.Changing those will get your code to execute. Preview of it working: