【发布时间】:2019-05-09 21:30:40
【问题描述】:
我正在使用这种方法(在堆栈溢出中找到)在清理 HMTL 视频时执行事件: Triggering Events from html5 video player with JQuery
完美运行。但是,我不知道如何在将视频时间线向后滑动到以前(较早)时间时触发不同的事件。我想关闭该事件,并可能在用户到达之前的原始时间时添加一个不同的事件。
我正在使用这种方法来“清理”时间线:
var windowwidth = $(window).width()-20;
var scrollpos = window.pageXOffset/200;
var targetscrollpos = scrollpos;
var accel = 0;
// ---- Values you can tweak: ----
var accelamount = 0.1; //How fast the video will try to catch up with the target position. 1 = instantaneous, 0 = do nothing.
// pause video on load
vid.pause();
window.onscroll = function(){
//Set the video position that we want to end up at:
targetscrollpos = window.pageXOffset/200;
};
setInterval(function(){
//Accelerate towards the target:
scrollpos += (targetscrollpos - scrollpos)*accelamount;
//update video playback
vid.currentTime = scrollpos;
vid.pause();
}, 60);
这个代码来自之前的堆栈溢出问题来触发事件
$(".boxB").animate({ marginLeft:'0px'},400);
$(".boxA").animate({ width:'620px'}, 400);
}
var runAtTime = function(handler, time) {
var wrapped = function() {
if(this.currentTime >= time) {
$(this).off('timeupdate', wrapped);
return handler.apply(this, arguments);
}
}
return wrapped;
};
$('#v0').on('timeupdate', runAtTime(myHandler, 3.5));
这里有一个工作版本: http://www.mediaflash.ca/swipe_video_timeline/index.html
该功能仅在您使用滚轮鼠标并在 iOS 设备上左右滚动或左右滑动时才有效。
【问题讨论】:
-
所以你想知道用户是否及时向后或向前擦洗?只需将上次看到的时间与您的元素一起存储,并在下一次擦洗事件中检查新时间是否大于或小于之前的时间。这是你想做的吗?
-
是的,我相信这正是我想要做的。我不知道该怎么做。你认为我可以挽救我目前使用的方法,还是应该完全使用不同的方法?我猜“如果(这个,currentTime