Docs
usePinchZoom

Enable pinch-to-zoom functionality on touch devices with usePinchZoom, providing options for min and max scale.

Loading...

Installation

pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-pinch-zoom

Usage

"use client"
 
import { usePinchZoom } from "@/hooks/use-pinch-zoom"
 
export function Component() {
  const { scale, isSupported, ...handlers } = usePinchZoom({
    onZoom: (s) => console.log("Zoom scale:", s),
    minScale: 0.2,
    maxScale: 4,
  })
 
  if (!isSupported) {
    return <div>Pinch zoom is not supported on this device.</div>
  }
 
  return (
    <div
      {...handlers}
      style={{
        transform: `scale(${scale})`,
        touchAction: "none",
        width: "100%",
        height: "100%",
        backgroundColor: "lightgray",
      }}
    >
      Pinch to zoom
    </div>
  )
}

API Reference

Parameters

NameTypeDescriptionDefault ValueOptional
onZoom() => voidCallback function when zooming occurs.undefinedYes
minScalenumberMinimum zoom scale.1Yes
maxScalenumberMaximum zoom scale.3Yes

Return Values

NameTypeDescription
scalenumberCurrent zoom scale.
onTouchStart() => voidTouch start event handler.
onTouchMove() => voidTouch move event handler.
onTouchEnd() => voidTouch end event handler.
isSupportedbooleanIndicates whether pinch zoom is supported.