Advertisement
afsarwebdev

Youtube video customized(button, video overlay as image)

Aug 29th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. //HTML & JS
  2. //Note that, data-id must be the same as iframe emnbeded id
  3. <div class="col-lg-12" id="ic-lazarVideoHolder">
  4. <div class="ic-youtube-player" data-id="su3k7Vk81oM">
  5. <script>
  6. document.addEventListener("DOMContentLoaded",
  7. function() {
  8. var div, n,
  9. v = document.getElementsByClassName("ic-youtube-player");
  10. for (n = 0; n < v.length; n++) {
  11. div = document.createElement("div");
  12. div.setAttribute("data-id", v[n].dataset.id);
  13. div.innerHTML = labnolThumb(v[n].dataset.id);
  14. div.onclick = labnolIframe;
  15. v[n].appendChild(div);
  16. }
  17. });
  18.  
  19. function labnolThumb(id) {
  20. var thumb = '<img src="assets/images/hqdefault.jpg">',
  21. play = '<div class="play"></div>';
  22. return thumb.replace("ID", id) + play;
  23. }
  24.  
  25. function labnolIframe() {
  26. var iframe = document.createElement("iframe");
  27. var embed = "https://www.youtube.com/embed/ID?autoplay=1&amp;rel=0&amp;controls=0&amp;showinfo=0";
  28. iframe.setAttribute("src", embed.replace("ID", this.dataset.id));
  29. iframe.setAttribute("frameborder", "0");
  30. iframe.setAttribute("allowfullscreen", "1");
  31. this.parentNode.replaceChild(iframe, this);
  32. }
  33. </script>
  34. </div>
  35. </div>
  36. //CSS
  37. #ic-lazarVideoHolder {
  38. margin-top: 10px;
  39. }
  40. .ic-youtube-player {
  41. position: relative;
  42. padding-bottom: 56.23%;
  43. height: 0;
  44. overflow: hidden;
  45. max-width: 100%;
  46. background: #000;
  47. }
  48. .ic-youtube-player iframe {
  49. position: absolute;
  50. top: 0;
  51. left: 0;
  52. width: 100%;
  53. height: 100%;
  54. z-index: 100;
  55. background: transparent;
  56. }
  57. .ic-youtube-player img:hover {
  58. -webkit-filter: brightness(75%);
  59. }
  60. .ic-youtube-player img {
  61. bottom: 0;
  62. display: block;
  63. left: 0;
  64. margin: auto;
  65. max-width: 100%;
  66. width: 100%;
  67. position: absolute;
  68. right: 0;
  69. top: 0;
  70. border: none;
  71. height: auto;
  72. cursor: pointer;
  73. -webkit-transition: .4s all;
  74. -moz-transition: .4s all;
  75. transition: .4s all;
  76. }
  77. .ic-youtube-player .play {
  78. height: 72px;
  79. width: 72px;
  80. left: 50%;
  81. top: 50%;
  82. margin-left: -36px;
  83. margin-top: -36px;
  84. position: absolute;
  85. background: url("../images/play.png") no-repeat;
  86. cursor: pointer;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement