Snapping to the edges of nearest elements

With PrimeFaces, we can snap the dragged component to the inner or outer boundaries of another component (a component's DOM element).

In this recipe, we will discuss snapping and its options in detail. As an example, we will develop a big h:panelGroup component as a snap target and three other small h:panelGroup components as draggable components, with various snapping options.

How to do it…

Generally, the snapping behavior is activated by setting the attribute snap to true. The snapping behavior is configurable with two options—snapMode and snapTolerance. The first option, snapMode, determines which edges of snap elements the draggable component will snap to. The second option, snapTolerance, determines ...

Get PrimeFaces Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.