0
私は循環型SVGスライダを作成しましたが、まだドットを正しく配置する際に問題があります。SVGスライダ - SVGパスに沿ってのみ移動ドット
HTML::
<svg version="1.1" id="slider" width="300px" height="150px">
<path id="sliderPath" stroke="red" stroke-width="5" d="M10,100a147,147,0,1,1,280,1"/>
<circle id="dot" fill="white" cx="10" cy="100" r="14" />
</svg>
JS:
var sliderPath = document.getElementById("sliderPath"),
box = sliderPath.getBBox(),
dot = document.getElementById("dot"),
W = box.width,
pathLength = sliderPath.getTotalLength();
Draggable.create(
document.createElement('div'),
{
type:'x',
throwProps:true,
bounds: { minX:0, maxX:W },
trigger:dot,
overshootTolerance:0,
onDrag:update,
onThrowUpdate:update
});
function update(){
// Get x and y for dot.
var P = sliderPath.getPointAtLength(this.x/W * pathLength);
// Set dot.
TweenLite.set(dot,{attr:{cx:P.x,cy:P.y}});
};
http://codepen.io/Yheeky/pen/xEbAbR
あなたは、ドットをドラッグを開始し、左からマウスを移動することができます はCodepen上の現在の結果を見てください右に。それはかなりうまくいくが、ドットの位置をマウスの位置と同じで、パスに沿ったものだけにするように、ドットの位置をより直接的に設定する必要がある。 このような結果を得るためには、何を変更する必要がありますか?
ありがとうございます!