Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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 在除Firefox之外的所有浏览器中,滚动播放视频都是平滑的_Javascript_Video_Html5 Video - Fatal编程技术网

Javascript 在除Firefox之外的所有浏览器中,滚动播放视频都是平滑的

Javascript 在除Firefox之外的所有浏览器中,滚动播放视频都是平滑的,javascript,video,html5-video,Javascript,Video,Html5 Video,按下#按钮时,使用currentTime根据滚动位置播放视频。视频编码正确,关键帧间隔为1,因此搜索不是问题。视频在除Firefox之外的所有浏览器中都能顺利播放,Firefox非常迟钝,我不知道为什么 使用滚动条或鼠标滚轮播放视频非常流畅。但是,按下#按钮会出现延迟 我已经为此挣扎了几天,所以任何帮助都将不胜感激 $(document).ready(function () { var intro = $("#intro"); var vid = $('#v0');

按下
#按钮
时,使用
currentTime
根据滚动位置播放视频。视频编码正确,关键帧间隔为1,因此搜索不是问题。视频在除Firefox之外的所有浏览器中都能顺利播放,Firefox非常迟钝,我不知道为什么

使用滚动条或鼠标滚轮播放视频非常流畅。但是,按下
#按钮
会出现延迟

我已经为此挣扎了几天,所以任何帮助都将不胜感激

$(document).ready(function () {
  var intro = $("#intro");
  var vid = $('#v0');
  var checkOnce = false;
  vid[0].load();
  
  vid.on('loadeddata', function () {
    // get height of each section text
    intro.children().each(function (index) {
      // insert next and prev buttons
      if (intro.children().length - 1 !== index) {
        $(this).find('span').append("<button id='button' class='btn btn-primary' data-position=" + (index + 2) + ">Next</button>");
      } else {
        $(this).find('span').append("<button id='button' class='btn btn-primary' data-position='end'>Next</button>");
      }
    });

    // required to remove the fixed height
    intro.css('marginBottom', vid.height());
  });

  $(window).scroll(function () {
    vid[0].currentTime = (window.pageYOffset / (intro.height() / 10));
    console.log(vid[0].currentTime);
    
    if ($(window).scrollTop() >= intro.offset().top + intro.outerHeight() - window.innerHeight + vid.height()) {
      if (checkOnce == false) {
        vid.css('position', 'relative');
        intro.css('marginBottom', 0);
        checkOnce = true;
      }
    } else {
      if (checkOnce == true) {
        intro.css('marginBottom', vid.height());
        vid.css('position', 'fixed');
        checkOnce = false;
      }
    }
  });

  $(document).on('click', '#button', function (event) {
    event.preventDefault();

    if ($(this).attr('data-position') === 'end') {
      $('html, body').animate({
        scrollTop: $(".end").offset().top
      }, 1500);
    } else {
      $('html, body').animate({
        scrollTop: $(".section" + $(this).attr('data-position')).offset().top
      }, 1500);
    }
  });
});
$(文档).ready(函数(){
var intro=$(“#intro”);
var vid=$('#v0');
var checkOnce=false;
vid[0]。加载();
vid.on('loadeddata',函数(){
//获取每个节文本的高度
intro.children().each(函数(索引){
//插入下一个和上一个按钮
if(intro.children().length-1!==索引){
$(this.find('span').append(“Next”);
}否则{
$(this.find('span').append(“Next”);
}
});
//需要移除固定高度
css('marginBottom',vid.height());
});
$(窗口)。滚动(函数(){
vid[0].currentTime=(window.pageYOffset/(intro.height()/10));
console.log(vid[0].currentTime);
if($(window.scrollTop()>=intro.offset().top+intro.outerHeight()-window.innerHeight+vid.height()){
if(checkOnce==false){
参见css(“位置”、“相对”);
简介css('marginBottom',0);
checkOnce=true;
}
}否则{
if(checkOnce==true){
css('marginBottom',vid.height());
参见css(“位置”、“固定”);
checkOnce=false;
}
}
});
$(文档)。在('单击','按钮')上,函数(事件){
event.preventDefault();
if($(this).attr('data-position')=='end'){
$('html,body')。设置动画({
scrollTop:$(“.end”).offset().top
}, 1500);
}否则{
$('html,body')。设置动画({
scrollTop:$(“.section”+$(this.attr('data-position')).offset().top
}, 1500);
}
});
});