Skip to main content

You can also declare event handlers inline:

App
<script>
	let m = $state({ x: 0, y: 0 });

	function onpointermove(event) {
		m.x = event.clientX;
		m.y = event.clientY;
	}
</script>

<div
	onpointermove={(event) => {
		m.x = event.clientX;
		m.y = event.clientY;
	}}
>
	The pointer is at {m.x} x {m.y}
</div>

Edit this page on GitHub

previous next
<script>
let m = $state({ x: 0, y: 0 });

function onpointermove(event) {
m.x = event.clientX;
m.y = event.clientY;
}
</script>

<div {onpointermove}>
The pointer is at {Math.round(m.x)} x {Math.round(m.y)}
</div>

<style>
div {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 1rem;
}
</style>