setX()

Manually set the x position of the draggable target.
Is equivalent updating draggable.x directly when no muteCallback parameter is defined.

Parameters

Name Type Description
x Number The new x value
muteCallback(opt) Boolean If true, prevents the onUpdate callback to fire (default false)

Returns

The draggable itself

setX() code example

import { createDraggable, utils } from 'animejs';

const [ $setButton ] = utils.$('.set');

const draggable = createDraggable('.square');

const setRandomX = () => draggable.setX(utils.random(-100, 100));

$setButton.addEventListener('click', setRandomX);
<div class="large centered row">
  <div class="square draggable"></div>
</div>
<div class="large row">
  <fieldset class="controls">
    <button class="button set">Set random x</button>
  </fieldset>
</div>