-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathResponsive Youtube Video with lazySize.html
78 lines (73 loc) · 3.36 KB
/
Responsive Youtube Video with lazySize.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Lazy Load Image And Embed Youtube Video With Jquery And LazySize.js</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
body {
padding:0 0 60px;
}
.video-box{margin-top:2000px}
img{width:auto;max-width:100%;height:auto}
</style>
</head>
<body>
<h1 class="text-center"><strong>Lazy Load Image And Embed Responsive Youtube Video</strong></h1>
<h2 class="text-center">With Jquery And LazySize.js</h2>
<div class="container">
<div class="row">
<h3><a class="btn btn-default btn-sm" href="http://www.kompiajaib.com/2017/02/cara-mudah-menggunakan-lazy-load.html" title="Back to article">Back to article</a></h3>
</div>
</div>
<hr>
<div class="container">
<div class="row">
<h4 class="text-center">Scroll down to see video</h4>
</div>
</div>
<div class="container video-box">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<img src="https://i.ytimg.com/vi/vUQkLrEjpm0/maxresdefault.jpg">
<br/>
<br/>
<br/>
<iframe width="560" height="315" src="https://www.youtube.com/embed/vUQkLrEjpm0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script async='async' src='https://cdn.rawgit.com/aFarkas/lazysizes/gh-pages/lazysizes.min.js' type='text/javascript'></script>
<script>
for(var imgEl=document.getElementsByTagName("img"),i=0;i<imgEl.length;i++)imgEl[i].getAttribute("src")&&(imgEl[i].setAttribute("data-src",imgEl[i].getAttribute("src")),imgEl[i].removeAttribute("src"),imgEl[i].setAttribute("src","data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="));console.log(document.body.innerHTML);
var images=document.getElementsByTagName("img"),i;for(i=0;i<images.length;i++)images[i].className+=" lazyload";
$("iframe[src*='youtube.com']").addClass("lazyload");
$(document).ready(function() {
$('iframe[src*="youtube.com"]').wrap('<div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;margin:0 auto;width:100%"></div>');
$('iframe[src*="youtube.com"]').css({
"position": "absolute",
"top": "0",
"left": "0",
"width": "100%",
"height": "100%",
"border": "0"
});
$('iframe[src*="youtube.com"]').each(function() {
$(this).attr("data-src", $(this).attr("src"));
$(this).removeAttr("src", "")
});
});
</script>
</body>
</html>