1.0.0 • Published 5 years ago

path-draggable-button v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

path-draggable-button

This jQuery plugin from LGND allows the user to drag a "button" (we typically use an image) along an SVG path, triggering an interaction when it reaches the end of the path.

Settings

OptionTypeDefaultDescription
pathSelectorstring"path"CSS selector for the SVG path to follow
directionstring"horizontal"Predominant direction of the path, either "horizontal" or "vertical"
negativebooleanfalseWhether the path is "reversed", e.g. bottom to top or right to left
thresholdfloat0.99Percentage (0.0-1.0) of the path the button needs to be dragged before triggering the handler

Events

EventArgumentsDescription
changeevent, button, valueWhen the button is dragged and changes position
finishevent, buttonWhen the button is dragged beyond the threshold percentage

Methods

Methods are called through the pathDraggableButton method, e.g.:

// Get percentage (0-1.0) dragged
var distance = $(".toggle-switch").pathDraggableButton('getValue');

// Set to 50% completed
$(".toggle-switch").pathDraggableButton('setValue', 0.5);
MethodArgumentDescription
getValueReturns the percentage (0-1.0) dragged
setValuevalue : floatSets the completion percentage (0-1.0) and moves the button along the path

Example

Create a draggable button that fades out after completion:

$(element).pathDraggableButton({
  direction: 'horizontal'
}).on('finish', function(){
  $(this).fadeOut();
});

For more examples, see https://lgndhq.github.io/path-draggable-button

Dependencies

jQuery 1.8