forked from findashu/Youtube-LazyLoading
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
33 lines (30 loc) · 1019 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<html>
<head>
<title>
Lazy Load Demo
</title>
<link type="text/css" rel="stylesheet" href="style.css"></link>
</head>
<body>
<div id="youtube" class="youtube">
<div class="play-button"></div>
</div>
</body>
</html>
<script type="text/javascript">
var youtube = document.getElementById("youtube");
var source ="https://img.youtube.com/vi/kF9NMCJFyHk/sddefault.jpg";
var image = new Image();
image.src = source;
image.addEventListener( "load", function() {
youtube.appendChild(image);
});
youtube.addEventListener( "click", function() {
var iframe = document.createElement( "iframe" );
iframe.setAttribute( "frameborder", "0" );
iframe.setAttribute( "allowfullscreen", "" );
iframe.setAttribute( "src", "https://www.youtube.com/embed/kF9NMCJFyHk?rel=0&autoplay=1");
this.innerHTML = "";
this.appendChild( iframe );
} );
</script>