I am working on creating a unique slider that allows users to click and drag a circle along a curved path. The functionality is almost there, but whenever I drag the circle to a certain position, it snaps back to its original location.
var s=Snap('svg');
animateAlongPath = function (path, element) {
var len = Snap.path.getTotalLength(path);
var move = function(dx) {
var movePoint=Snap.path.getPointAtLength(path, dx);
this.attr({ cx: movePoint.x, cy: movePoint.y });
}
element.drag(move)
}
var path=s.path('M10 200 q 120 -120 140 0 t 140 0').attr({
fill:'none',
stroke:'black'
});
var circle=s.circle(10,200,5);
animateAlongPath(path,circle)
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.3.0/snap.svg-min.js"></script>
<svg width="500" height="500" ></svg>
Example image