小编gas*_*par的帖子

确切的显示时间:requestAnimationFrame的用法和时间线

我要实现的是检测屏幕上出现某些更改的准确时间(主要是使用Google Chrome浏览器)。例如,我使用显示项目$("xelement").show();或使用进行更改$("#xelement").text("sth new");,然后我想查看Performance.now()到底是什么,当更改以给定的屏幕重新绘制出现在用户的屏幕上时。因此,我完全可以接受任何解决方案-在下文中,我主要指的是requestAnimationFrame(rAF),因为这是应该帮助实现此功能的函数,只是似乎没有实现。见下文。

基本上,正如我所想象的,rAF应该在0-17毫秒内执行其中的所有操作(每当下一帧出现在我的标准60 Hz屏幕上)。此外,timestamp参数应提供此执行时间的值(并且该值基于与performance.now()相同的DOMHighResTimeStamp度量)。

现在,这是我为此进行的众多测试之一:https : //jsfiddle.net/gasparl/k5nx7zvh/31/

function item_display() {
    var before = performance.now();
    requestAnimationFrame(function(timest){
        var r_start = performance.now();
        var r_ts = timest;
        console.log("before:", before);
        console.log("RAF callback start:", r_start);
        console.log("RAF stamp:", r_ts);
        console.log("before vs. RAF callback start:", r_start - before);
        console.log("before vs. RAF stamp:", r_ts - before);
        console.log("")
    });
}
setInterval(item_display, Math.floor(Math.random() * (1000 - 500 + 1)) + 500);
Run Code Online (Sandbox Code Playgroud)

我在Chrome中看到的是:rAF内的函数总是在大约0到3毫秒内执行(从紧接其前的performance.now()开始),最奇怪的是,rAF时间戳与我得到的完全不同rAF内的performance.now()通常比在rAF 之前调用的performance.now()早大约0-17毫秒(但有时在之后0-1毫秒)。

这是一个典型的例子:

before: 409265.00000001397
RAF callback start: 409266.30000001758
RAF stamp: 409260.832 
before …
Run Code Online (Sandbox Code Playgroud)

javascript animation timing requestanimationframe display

5
推荐指数
1
解决办法
362
查看次数

ionic 3中的touchstart和touchend事件

我正在Ionic 3中寻找单独的事件处理程序,以开始和结束对移动应用程序上HTML元素的触摸。

我发现了许多相关且已解决的问题,但对于Ionic 3却没有,目前似乎仅支持“点击,按下,平移,滑动,旋转和捏合”(https://ionicframework.com/docs/components/#gestures) 。这些似乎都没有在开始时提供“处理程序”,而只是在结束时提供了“处理程序”。我看到,然后它们确实提供了触摸持续时间(deltaTime)的数据,但是到那时为止,这对我而言毫无用处。

要获得更多背景信息,我想清除的是在第一次触摸某个元素的确切时间里的相关超时,然后查看同一特定元素上的触摸是否在一定时间内(例如250毫秒,以便可以将其评估为“点击”)。

例如这样的事情:

JS:

timeout_1 = setTimeout(function() {
    // do something if timeout_1 not cleared by touch start
}, 4000);

touched(event) {
    clearTimeout(timeout_1);
    touching_x = true
    timeout_2 = setTimeout(function() {
        touching_x = false
        // store event details and do other things if timeout_2 not cleared by touch end
    }, 250);
}

touch_ended(event) { 
    if (touching_x==true) {
        clearTimeout(timeout_2);    
        // store event details and do some other things
    }
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<button ion-button type="button" (button_touch_started) = …
Run Code Online (Sandbox Code Playgroud)

html javascript-events touch touchstart ionic3

0
推荐指数
1
解决办法
6807
查看次数