Tengo este código que me permite detener la reproducción de videos de YouTube una vez que se presiona un botón. Aquí hay un ejemplo:
//Hotel Post <script> $(document).ready(function() { // set unique id to videoplayer for the Webflow video element var src = $('#videoplayer').children('iframe').attr('src'); // when object with class open-popup is clicked... $('.open-popup.left').click(function(e) { e.preventDefault(); // change the src value of the video $('#videoplayer').children('iframe').attr('src', src); $('.popup-bg').fadeIn(); }); // when object with class close-popup is clicked... $('.close-modal-button').click(function(e) { e.preventDefault(); $('#videoplayer').children('iframe').attr('src', ''); $('.popup-bg').fadeOut(); }); }); </script> //Gans to go <script> $(document).ready(function() { // set unique id to videoplayer for the Webflow video element var src = $('#videoplayer2').children('iframe').attr('src'); // when object with class open-popup is clicked... $('.open-popup.left').click(function(e) { e.preventDefault(); // change the src value of the video $('#videoplayer2').children('iframe').attr('src', src); $('.popup-bg').fadeIn(); }); // when object with class close-popup is clicked... $('.close-modal-button').click(function(e) { e.preventDefault(); $('#videoplayer2').children('iframe').attr('src', ''); $('.popup-bg').fadeOut(); }); }); </script>Tengo alrededor de 14 videos como este incrustados en mi sitio y hace que las cosas sean más lentas, porque tengo uno de estos scripts para cada video. ¿Hay alguna manera de que pueda seleccionar varias identificaciones a la vez o algo así? Entonces, ¿tengo un guión para todos los videos?
Apreciaría la ayuda. Muchas gracias. Pablo
Una forma es configurar todos los videos para que tengan un nombre de clase común, como video y almacenar la variable src en un atributo de datos.
$(document).ready(function() { // set unique id to videoplayer for the Webflow video element $('.video').each(function() { let src = $(this).children('iframe').attr('src'); $(this).attr('data-src', src); }) // when object with class open-popup is clicked... $('.open-popup.left').click(function(e) { e.preventDefault(); // change the src value of the video $('.video').each(function() { $(this).children('iframe').attr('src', $(this).data('src')); $('.popup-bg').fadeIn(); }); // when object with class close-popup is clicked... $('.close-modal-button').click(function(e) { e.preventDefault(); $('.video').each(function() { $(this).children('iframe').attr('src', ''); $('.popup-bg').fadeOut(); }); });