1.0.0 • Published 2 years ago

svelte-dodge v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Svelte-Dodge

Make components dodge the pointer.

About

  • Written in Svelte with Typescript
  • No external 3rd party dependencies
  • Easy-to-use by just wrapping any element or component
  • Dispatches movement events
  • Multiple movement modes
  • Supply custom movement functions using available helpers

Installation

npm i -D svelte-dodge

Usage

<script>
  import { Dodge } from 'svelte-dodge'; 
</script>

<Dodge>
  <div>
    This dodges now
  </div>
</Dodge>

Props

PropDefaultDescription
activationDistance20Activation distance in px.
boxright 400, rest 0Size of possible movement area (additional to element size) in px in the directions up, down, left and right.
customMovement...Supply a custom movement function. Set mode to 'custom' to use.
dodgetrueToggle the movement.
duration0.3Transition duration in s when movement is triggered. If set to 0 no transition is used.
mode'kite-flip'See movement.
moveDistance100Additional movement in the desired direction when activated.
rate0.1Update rate on cursor position and movement trigger detection in ms. If set to 0 it uses the native browser rate.

Events

EventDescription
moveTriggered whenever movement function is called with cursor close enough.
transitionstartTriggered whenever element transition starts. Only if duration > 0.
transitionendTriggered whenever element transition ends. Only if duration > 0.

Movement

Movement is triggered whenever the cursor moves inside the activation area. It is also triggered when a click happens in the activation area. Movement can be disabled with the 'dodge' flag.

ValueDescription
'custom'Use the custom prop to supply a custom movement function. It takes box, element and cursor and should output new x,y coordinates for the element.
'kite'Move away from cursor. When edge of area is reached flip to other side of area.
'kite-flip'Move away from cursor. When edge of area is reached flip to other side of cursor.
'random'Move to random spot im movement area when triggered. Make sure the cursor is not inside element after moving.
1.0.0

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago