Skip to content
/ d3-zoom Public

Pan and zoom SVG, HTML or Canvas using mouse or touch input.

License

Notifications You must be signed in to change notification settings

d3/d3-zoom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

d3-zoom

Installing

If you use NPM, npm install d3-zoom. Otherwise, download the latest release. You can also load directly from d3js.org, either as a standalone library or as part of D3 4.0. AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3_zoom global is exported:

<script src="https://d3js.org/d3-color.v0.4.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v0.4.min.js"></script>
<script src="https://d3js.org/d3-ease.v0.7.min.js"></script>
<script src="https://d3js.org/d3-interpolate.v0.8.min.js"></script>
<script src="https://d3js.org/d3-selection.v0.7.min.js"></script>
<script src="https://d3js.org/d3-timer.v0.4.min.js"></script>
<script src="https://d3js.org/d3-transition.v0.2.min.js"></script>
<script src="https://d3js.org/d3-drag.v0.1.min.js"></script>
<script src="https://d3js.org/d3-zoom.v0.0.min.js"></script>
<script>

var zoom = d3_zoom.zoom();

</script>

Try d3-zoom in your browser.

API Reference

This table describes how the zoom behavior interprets native events:

Event Listening Element Zoom Event Default Prevented?
mousedown⁵ selection start no¹
mousemove² window¹ zoom yes
mouseup² window¹ end yes
dragstart² window - yes
selectstart² window - yes
click³ window - yes
dblclick selection multiple yes
wheel selection zoom⁷ yes
touchstart selection multiple no⁴
touchmove selection zoom yes
touchend selection end no⁴
touchcancel selection end no⁴

The propagation of all consumed events is immediately stopped.

¹ Necessary to capture events outside an iframe; see d3-drag#9.
² Only applies during an active, mouse-based gesture; see d3-drag#9.
³ Only applies immediately after a non-empty, mouse-based gesture.
⁴ Necessary to allow click emulation on touch input; see d3-drag#9.
⁵ Ignored if within 500ms of a touch gesture ending; assumes click emulation.
⁶ Double-click and double-tap initiate a transition that emits start, zoom and end events.
⁷ The first wheel event emits a start event; an end event is emitted when no wheel events are received for 150ms.

# d3.zoom()