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의 현재 결과에서보세요 오른쪽으로. 잘 작동하지만 도트 위치가 마우스 위치와 동일하지만 경로를 따라 더 가며 점 위치를보다 직접 설정해야합니다. 이런 종류의 결과를 얻으려면 무엇을 변경해야합니까?
미리 감사드립니다.