Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/09/2016, 09:31
txemaker
 
Fecha de Ingreso: octubre-2007
Mensajes: 74
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: problema al incrustar un segundo video con CSS + SCRIPT

Cita:
Iniciado por mpozo Ver Mensaje
El método getElementsByClassName retorna un classList y para acceder a cada elemento se usa un índice. Cómo puedes ver, en tu código, el índice es 0. Esto quiere decir que cualquier cosa que se haga sólo afectara al primer elemento.

La solución es usar el método querySelectorAll(), por que getElementsByClassName() está obsoleto, y recorrer el la colección de elementos con un ciclo (for o forEach)


hola mpozo gracias por responder... disculpa, es que estoy limitado en javascript.... he probado con esto:


Código Javascript:
Ver original
  1. var videoPlayButton,
  2.     videoWrapper = document.querySelectorAll()('video-wrapper'),
  3.     video = document.querySelectorAll()('video'),
  4.     videoMethods = {
  5.         renderVideoPlayButton: function() {
  6.             if (videoWrapper.contains(video)) {
  7.                 this.formatVideoPlayButton()
  8.                 video.classList.add('has-media-controls-hidden')
  9.                 videoPlayButton = document.querySelectorAll()('video-overlay-play-button')
  10.                 videoPlayButton.addEventListener('click', this.hideVideoPlayButton)
  11.             }
  12.         },
  13.  
  14.         formatVideoPlayButton: function() {
  15.             videoWrapper.insertAdjacentHTML('beforeend', '\
  16.                <svg class="video-overlay-play-button" viewBox="0 0 200 200" alt="Play video">\
  17.                    <circle cx="100" cy="100" r="90" fill="none" stroke-width="15" stroke="#fff"/>\
  18.                    <polygon points="70, 55 70, 145 145, 100" fill="#fff"/>\
  19.                </svg>\
  20.            ')
  21.         },
  22.  
  23.         hideVideoPlayButton: function() {
  24.             video.play()
  25.             videoPlayButton.classList.add('is-hidden')
  26.             video.classList.remove('has-media-controls-hidden')
  27.             video.setAttribute('controls', 'controls')
  28.         }
  29.     }
  30.  
  31. videoMethods.renderVideoPlayButton()


pero no funciona en ninguno... por favor, podrias ponerme el script completo??? mil gracias de verdad...

te pongo de nuevo el script original


Código Javascript:
Ver original
  1. var videoPlayButton,
  2.     videoWrapper = document.getElementsByClassName('video-wrapper')[0],
  3.     video = document.getElementsByTagName('video')[0],
  4.     videoMethods = {
  5.         renderVideoPlayButton: function() {
  6.             if (videoWrapper.contains(video)) {
  7.                 this.formatVideoPlayButton()
  8.                 video.classList.add('has-media-controls-hidden')
  9.                 videoPlayButton = document.getElementsByClassName('video-overlay-play-button')[0]
  10.                 videoPlayButton.addEventListener('click', this.hideVideoPlayButton)
  11.             }
  12.         },
  13.  
  14.         formatVideoPlayButton: function() {
  15.             videoWrapper.insertAdjacentHTML('beforeend', '\
  16.                <svg class="video-overlay-play-button" viewBox="0 0 200 200" alt="Play video">\
  17.                    <circle cx="100" cy="100" r="90" fill="none" stroke-width="15" stroke="#fff"/>\
  18.                    <polygon points="70, 55 70, 145 145, 100" fill="#fff"/>\
  19.                </svg>\
  20.            ')
  21.         },
  22.  
  23.         hideVideoPlayButton: function() {
  24.             video.play()
  25.             videoPlayButton.classList.add('is-hidden')
  26.             video.classList.remove('has-media-controls-hidden')
  27.             video.setAttribute('controls', 'controls')
  28.         }
  29.     }
  30.  
  31. videoMethods.renderVideoPlayButton()