gotovideo.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. $(".video-img").click(function () {
  2. var videosrc = $(this).data("info");
  3. console.log(videosrc);
  4. let VideoContent = `
  5. <style>
  6. .embed-container {
  7. position: relative;
  8. padding-bottom: 56.25%;
  9. height: 0;
  10. overflow: hidden;
  11. max-width: 100%;
  12. }
  13. .embed-container iframe,
  14. .embed-container object,
  15. .embed-container embed {
  16. position: absolute;
  17. top: 0;
  18. left: 0;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. </style>
  23. <div class='embed-container'><iframe class='youtube-video' src='${videosrc}'
  24. frameborder='0' allowfullscreen></iframe></div>
  25. `;
  26. $('#video-modal').html(VideoContent);
  27. });
  28. $('.play-video').click(function(){
  29. $('.youtube-video')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
  30. });
  31. // function autoPlayYouTubeModal() {
  32. // var trigger = $("body").find('[data-toggle="modal"]');
  33. // trigger.click(function () {
  34. // var theModal = $(this).data("target"),
  35. // videoSRC = $(this).attr("data-theVideo"),
  36. // videoSRCauto = videoSRC + "?autoplay=1";
  37. // $(theModal + ' iframe').attr('src', videoSRCauto);
  38. // $(theModal + ' button.close').click(function () {
  39. // $(theModal + ' iframe').attr('src', videoSRC);
  40. // });
  41. // });
  42. // }
  43. $(document).on("click", ".btn-close", function (event) {
  44. $('.youtube-video').each(function () {
  45. this.contentWindow.postMessage('{"event": "command", "func": "stopVideo", "args": ""}', '*');
  46. });
  47. console.log('stop');
  48. });
  49. $(document).on("click", "#exampleModal", function (event) {
  50. $('.youtube-video').each(function () {
  51. this.contentWindow.postMessage('{"event": "command", "func": "stopVideo", "args": ""}', '*');
  52. });
  53. // alert('111111')
  54. // window.location.reload();
  55. });