Skip to example

Drag

An example of making an element draggable with Motion's drag() function.

JavaScript

Source code

<div class="box"></div>

<script type="module">
    import { drag } from "motion"

    drag(".box")
</script>

<style>
    .box {
        width: 120px;
        height: 120px;
        background-color: var(--accent);
        cursor: grab;
    }

    .box:active {
        cursor: grabbing;
    }
</style>