- All available props
- Configure
children: React$Elementinertia: booleaninertiaFriction: numberenabled: booleanisTouch?: () => booleanshouldCancelHandledTouchEndEvents?: booleanshouldInterceptWheel?: (WheelEvent) => booleanwheelScaleFactor: numbertapZoomFactor?: numberzoomOutFactor?: numberdoubleTapZoomOutOnMaxScale?: booleandoubleTapToggleZoom?: booleananimationDurationmaxZoom?: numberminZoom?: numberenforceBoundsDuringZoom?: booleancenterContained?: booleandraggableUnZoomed?: booleandoubleTapZoomOutOnMaxScale?: booleanlockDragAxis?: booleannonce?: stringsetOffsetsOnce?: booleanverticalPadding?: numberhorizontalPadding?: number
- Event
- Methods
Below are listed all available properties with their default values (* except events of course)
import QuickPinchZoom from "react-quick-pinch-zoom";
<QuickPinchZoom
// `onUpdate` is one required prop
onUpdate={({ scale, x, y }) => console.log(" --- onUpdate", { scale, x, y })}
inertia={true}
inertiaFriction={0.96}
tapZoomFactor={1}
zoomOutFactor={1.3}
animationDuration={250}
maxZoom={5}
minZoom={0.5}
enforceBoundsDuringZoom={false}
centerContained={false}
draggableUnZoomed={true}
doubleTapZoomOutOnMaxScale={false}
doubleTapToggleZoom={false}
lockDragAxis={false}
nonce={undefined}
setOffsetsOnce={false}
verticalPadding={0}
horizontalPadding={0}
onZoomStart={() => console.log(" --- onZoomStart")}
onZoomEnd={() => console.log(" --- onZoomEnd")}
onZoomUpdate={() => console.log(" --- onZoomUpdate")}
onDragStart={() => console.log(" --- onDragStart")}
onDragEnd={() => console.log(" --- onDragEnd")}
onDragUpdate={() => console.log(" --- onDragUpdate")}
onDoubleTap={() => console.log(" --- onDoubleTap")}
/>;Children must has only one child (a React element)!
Inertia allows drag and resize actions to continue after the user releases the pointer at a fast enough speed.
(default true)
Is a number greater than zero and less than 1 which sets the rate at which the action slows down.
Smaller values slow it down more quickly.
(default 0.96)
Flag that let listen touch\mouse events. (default true)
Function helper that detect support touch events.
When function return true component start listen touch events
otherwise mouse events and wheel.
// default
const isTouch = () => "ontouchstart" in window || navigator.maxTouchPoints > 0;Cancel touchEnd events when this library makes any visual changes.
(default false)
Using true allows to bubble the touchEnd event only when no visual changes have been made.
This function will called when isTouch() return false and user the user will scroll over the element.
By default component Intercept wheel event with holding Crtl or Cmd
// default
const shouldInterceptWheel = event => !(event.ctrlKey || event.metaKey);This ratio indicate how fast the zoom will change when scrolling over the element.
(default 1500)
Zoom factor that will be added for current zoom Factor when a double tap zooms to.
A value of 0 will disable double tap handling.
(default 1)
Resize to original size when the zoom factor is below this value.
(default 1.3)
Zoom out on double tap if scale same as max scale
(default false)
Zoom out on double tap if zoomed in. Allows zooming in and back out with two consecutive double taps.
(default false)
Animation duration in milliseconds. (default 250)
Maximum zoom factor. (default 5)
Minimum zoom factor. (default 0.5)
While zooming, do not allow moving image to positions it cannot be dragged to.
(default false)
Center image, when it does not cover that container (e.g., when the container has a fixed size or when the image is scaled down below its initial size using a pinch gesture).
(default false)
Capture drag events even when the image isn't zoomed.
(default true)
Zoom back out on double tap when the image is fully zoomed in.
(default false)
Using false allows other libs to pick up drag events
Lock panning of the element to a single axis.
(default false)
Optional CSP nonce for injecting required CSS into the document.
(default undefined)
Compute offsets (image position inside container) only once.
(default true)
Using true maintains the offset on consecutive load and resize
Vertical padding to apply around the passed DOM element. (default 0)
Horizontal padding to apply around the passed DOM element. (default 0)
Required property.
It will be called when change scale or translate coordinates.
Update will be called no more than one render frame.
Callback for zoom start event
Callback for zoom end event
Callback for zoom update event
Callback for drag start event
Callback for drag end event
Callback for drag update event
Callback for doubletap event on touch devise or doubleclick event on desktop
type OptionsType = {
x: number,
y: number,
scale: number,
animated?: boolean, // not required, default: `true`
duration?: number // not required, default: `250`
};x, y is the relative coordinates by a container
With this method, we can increase relative to any point
With this method we can align any point in the middle of the screen