我正在制作可自动播放视频的脚本。我试过了,但是没有用。我在下面附加了我的代码和测试链接,以进行更多说明。
window.addEventListener("scroll", videoPlay);
function videoPlay(){
var scrollTop = jQuery(window).scrollTop();
var elementOffset = jQuery("#my_video_1").offset().top;
distance = ( elementOffset - scrollTop );
if(distance <= 250){
let player = document.querySelector("#my_video_1");
player.muted= true;
player.play();
// return player
}
}
https://play.golang.org/p/0atlGVCL-px
请对此提供帮助。谢谢:)
答案 0 :(得分:0)
检查
window.addEventListener("scroll", videoPlay);
function videoPlay(){
var scrollTop = jQuery(window).scrollTop();
var elementOffset = jQuery("#my_video_1").offset().top;
distance = ( elementOffset - scrollTop );
if(distance <= 250){
var myPlayer = videojs('my_video_1');
myPlayer.play();
jQuery("#my_video_1").addClass("vjs-playing");
}
}