gpt4 book ai didi

javascript - D3 补间 - 暂停和恢复控件

转载 作者:行者123 更新时间:2023-12-03 10:42:48 25 4
gpt4 key购买 nike

我正在尝试编辑此d3 example .

更具体地说,我将尝试应用pause resume guide的暂停-恢复控件。除了像这样的控制栏外,我们还在视频下提供了控制栏。最后我想有这样的事情:

Pause Resume Controls

如何在开始时应用暂停恢复控制?

最佳答案

这是一个快速实现。暂停本质上取消了当前的转换,并且播放根据暂停的时间/位置恢复它:

var pauseValues = {
lastT: 0,
currentT: 0
};
function transition() {
circle.transition()
.duration(duration - (duration * pauseValues.lastT)) // take into account any pause
.attrTween("transform", translateAlong(path.node()))
.each("end", function(){
pauseValues = {
lastT: 0,
currentT: 0
};
transition()
});
}
function translateAlong(path) {
var l = path.getTotalLength();
return function(d, i, a) {
return function(t) {
t += pauseValues.lastT; // was it previously paused?
var p = path.getPointAtLength(t * l);
pauseValues.currentT = t; // just in case they pause it
return "translate(" + p.x + "," + p.y + ")";
};
};
}
d3.select('button').on('click',function(d,i){
var self = d3.select(this);
if (self.text() == "Pause"){
self.text('Play');
circle.transition()
.duration(0);
setTimeout(function(){
pauseValues.lastT = pauseValues.currentT; // give it a bit to stop the transition
}, 100);
}else{
self.text('Pause');
transition();
}
});
transition();

示例 here .

关于javascript - D3 补间 - 暂停和恢复控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com