A modern SvelteKit application demonstrating the integration of interact.js for creating draggable and resizable elements using Svelte 5's new reactivity system.
$state
and $effect
# Clone the repository
git clone https://github.com/quang-design/svelte-interactjs.git
cd svelte-interactjs
# Install dependencies
npm install
# or
pnpm install
# or
yarn install
Start the development server:
npm run dev
# Or start the server and open the app in a new browser tab
npm run dev -- --open
Create a production build:
npm run build
Preview the production build:
npm run preview
<script lang="ts">
import interact from 'interactjs';
import type { Action } from 'svelte/action';
// Use Svelte 5's reactive state
const position = $state({ x: 0, y: 0 });
// Create a Svelte action for draggable functionality
const draggable: Action<HTMLDivElement> = (node) => {
// Implementation details...
$effect(() => {
const interaction = interact(node)
.draggable({
// Draggable options...
})
.resizable({
// Resizable options...
});
return () => {
interaction.unset();
};
});
};
</script>
<div use:draggable class="your-styling-here">
Draggable and Resizable Element
</div>
src/routes/
- SvelteKit routessrc/lib/
- Reusable components and utilitiesstatic/
- Static assetsMIT