Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 刷新页面时,HTML视频不在悬停状态下播放_Javascript_Jquery_Html - Fatal编程技术网

Javascript 刷新页面时,HTML视频不在悬停状态下播放

Javascript 刷新页面时,HTML视频不在悬停状态下播放,javascript,jquery,html,Javascript,Jquery,Html,基本上,我有一个页面,里面有一些视频, 因此,当我在任何视频上悬停时,它应该播放,当我从视频中鼠标移出时,它应该停止。 当我第一次访问页面或进行硬刷新时,一切正常。 但当我通过刷新重新加载同一页面时,或者当我在浏览器中再次点击页面url时, 悬停时不播放视频。而且,当我在重新加载页面后,在视频之外的其他地方单击鼠标按钮,然后将鼠标悬停在视频上时,也会再次工作 以下是我正在使用的代码:- <div class="vid" > <video width="100%" heigh

基本上,我有一个页面,里面有一些视频, 因此,当我在任何视频上悬停时,它应该播放,当我从视频中鼠标移出时,它应该停止。 当我第一次访问页面或进行硬刷新时,一切正常。 但当我通过刷新重新加载同一页面时,或者当我在浏览器中再次点击页面url时, 悬停时不播放视频。而且,当我在重新加载页面后,在视频之外的其他地方单击鼠标按钮,然后将鼠标悬停在视频上时,也会再次工作

以下是我正在使用的代码:-

 <div  class="vid" >
<video width="100%" height="100%" class="thevideo" >
<source src="some path" >
</video>
</div>

<script type="text/javascript">
 var figure = $(".vid").hover( hoverVideo, hideVideo);
   function hoverVideo(e) { $('.thevideo', this).get(0).play();  
    }
   function hideVideo(e) {
       $('.thevideo', this).get(0).pause();
       $('.thevideo', this).get(0).currentTime=0;
    }

</script>

变量图=$(“.vid”).hover(hoverVideo,hideVideo);
函数hoverVideo(e){$('.thevideo',this.get(0.play();
}
函数hideVideo(e){
$('.thevideo',this.get(0.pause();
$('.thevideo',this.get(0).currentTime=0;
}

试着用
$(document.ready()
像这样包装代码

$(document).ready(function(){
   var figure = $(".vid").hover( hoverVideo, hideVideo);
   function hoverVideo(e) { $('.thevideo', this).get(0).play();  
    }
   function hideVideo(e) {
       $('.thevideo', this).get(0).pause();
       $('.thevideo', this).get(0).currentTime=0;
    }
})

感谢您的回复,我尝试了您的解决方案,但当我访问页面后再次点击url时,悬停仍然不起作用