OBJETIVO: Intentar reproducir automáticamente cuando el mouse está sobre el video.
HTML:
<video id = "litVideo" src="lt.mp4" onmouseover="over(this)" onmouseout="out(this)" controls>JAVASCRIPT:
function over(element) { alert("mouseover"); element.append(autoplay) **also tried element.add(autoplay)** } function out(element) { alert("mouseout"); element.remove(autoplay); }Problema: Mouseover está alertando. Sin embargo, la reproducción automática no funciona . Por favor ayuda.
use la función reproducir () y pausa ()
const video = document.getElementById("video") video.onmouseover = function(){ video.play() } video.onmouseout = function(){ video.pause() } <video src="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" controls id="video"></video>Sin embargo, si desea utilizar su enfoque, utilice
elemento.setAttribute("reproducción automática")