javascript - 我怎样才能让这个视频流畅地滚动?
问题描述
该视频具有较高的关键帧间隔(设置为 1),因此搜索不是问题。它在我的本地主机上平滑滚动,但在生产中落后。这是一个演示。任何帮助将不胜感激,因为我已经坚持了一段时间。
我的目标是让视频流畅滚动,没有延迟。我正在使用获取请求,以便我可以先下载整个视频以帮助提高流畅度,但它似乎不起作用。这是我的代码:
$(document).ready(function () {
var vid = $('#v0');
var url = "videos/video.mp4";
var intro = $("#intro");
var spinner = $(".spinner-border").closest("div");
var checkOnce = false;
var videoLength = $('.heading').length * 2;
vid.hide();
spinner.hide();
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onload = function (oEvent) {
var blob = new Blob([oEvent.target.response], { type: "video/mp4" });
vid.src = URL.createObjectURL(blob);
vid[0].play();
// required to remove the fixed height
intro.css('marginBottom', vid.height());
// refresh video frames on interval for smoother playback
setInterval(function () {
vid[0].pause();
vid[0].currentTime = (window.pageYOffset / (intro.height() / videoLength));
// change video position to fixed or relative when scrolling past container
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;
}
}
}, 40);
};
xhr.onprogress = function (oEvent) {
if (oEvent.lengthComputable) {
var progress = oEvent.loaded / oEvent.total;
if (progress < 1) {
spinner.show();
vid.fadeOut();
} else {
spinner.hide();
vid.fadeIn();
}
}
}
xhr.send();
});
解决方案
推荐阅读
- jenkins - 我如何将 git 凭据添加到 jenkins 声明性管道中
- python - 我收到 result_sheet =result_xlsx.active AttributeError: 'Workbook' object has no attribute 'active' 错误
- python - 熊猫仅在满足条件时才对列应用方法
- r - 如何从 R 中的数据框中删除所有没有内容的变量/列?
- pdf - 如何在 Linux (Mac) 中从 WORD 文档中提取嵌入的 PDF
- r - 为什么我的 .nc 文件的尺寸在 R 中无法识别?
- raspberry-pi - 防止 Raspberry Pi 4 进入睡眠/关机状态(Ubuntu Server 18.04)
- javascript - 为对象的键分配多个值
- rust - 在 Rust 中定义可以返回多种错误类型的函数
- google-apps-script - 在 iframe 中部署反应后的 Web 应用程序不同