简体   繁体   中英

d3 transition not following path

I like to make the aircraft follow the path. But whatever I have tried there is a shift between the transition path and the actual drawn path on the screen. Please look at the jsfiddle

d3.selectAll('.aircraft').transition()
.duration(7500)
.attrTween('transform', translateAlong(d3.select('#samplePath').node()))

function translateAlong(path) {
    let l = path.getTotalLength()
        // debugger
        return function (i) {
        return function (t) {
            let p = path.getPointAtLength(t * l)
                console.log(p.x, p.y)
                return 'matrix(-0.359863 -0.230143 0.230143 -0.359863' + p.x + ' ' + p.y + ')'
        }
    }
}

您在矩阵定义中的第二个-0.359863之后缺少空格:

return 'matrix(-0.359863 -0.230143 0.230143 -0.359863 ' +  p.x + ' ' + p.y + ')'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM