13.4 Scripting SVG

13.4.2 Events overview

Interaction occurs when graphic objects respond to events. There are several categories of events. The text for many of these descriptions comes directly from the World Wide Web Consortium's specification.

Types of events

User interface events
The focusIn and focusOut events occur when an element receives or loses focus, such as selecting or unselecting text. The activate element occurs when an element is activated through a mouse click or keypress.
More www.w3.org
Mouse events
The mousedown and mouseup events occur when a pointing device button is pressed or released on an element. If the screen location for these events is the same, then a click event is generated.
The mouseover, mousemove, and mouseout events occur when the pointing device is moved over an element, moved while over an element, and moved away from an element
Mutation events
The SVG viewer will generate events when the DOM changes (by another script); for example,
  • DOMNodeInserted occurs when a node has been added as a child of another node;
  • DOMAttrModified occurs when an attribute has been modified on a node.
Document events
  • The SVGLoad event is triggered when the SVG viewer has fully parsed a document and is ready to act upon it (e.g., display it on a device).
  • SVGUnload occurs when a document is removed from a window.
  • SVGAbort occurs when page loading is stopped before loading completes;
  • SVGError occurs when an element does not load properly or an error occurs during script execution.
  • The SVGResize, SVGScroll, and SVGZoom events occur when the viewer changes the document in the way that the name suggests.
Animation events
The SVG viewer generates beginEvent, endEvent, and repeatEvent when an animation element begins, ends, or repeats; repeatEvent is not generated for the first iteration.
Key events
There are no events built into SVG for keypresses, but some viewers may support nonstandard keydown and keyup events.