Skip to content

Grab, lock and pannability

Inspect active state and control which elements can move through gestures.

#Selection and interaction state

Selections and interaction state (selected, locked, grabbable, pannable, emphasis and visibility) are element state. They can be queried and mutated through collection methods. Classes and class strings are unsupported. Use data, query predicates and declarative style conditions instead.

#ele.grabbable()

// Pannable elements are not draggable, so pannable overrides grabbable
ele.grabbable(): boolean

Pannable elements are not draggable, so pannable overrides grabbable .

Returns boolean

whether a drag gesture would move this element — the effective answer, so a grabbable-but-pannable element reads false here while json() reports the raw field

Example

console.log(eles.grabbable()); // true

Example graph and handle setup

#ele.grabbed()

// Whether the first element is currently held by a drag gesture
ele.grabbed(): boolean

Whether the first element is currently held by a drag gesture.

Returns boolean

true while grabbed

Example

console.log(eles.grabbed()); // false

Example graph and handle setup

#eles.grabify()

// Make these elements grabbable
eles.grabify(): this

Make these elements grabbable.

Returns this

this collection, for chaining

Example

const node = cy.getElementById('a');
node.grabify();
console.log(node.grabbable()); // true

Example graph and handle setup

#eles.ungrabify()

// Make these elements ungrabbable — the user can no longer drag them, while programmatic position writes still apply
eles.ungrabify(): this

Make these elements ungrabbable — the user can no longer drag them, while programmatic position writes still apply.

Returns this

this collection, for chaining

Example

const node = cy.getElementById('a');
node.ungrabify();
console.log(node.grabbable()); // false

Example graph and handle setup

#ele.locked()

// Whether the first element is locked — immovable, by layouts, position writes and position tweens alike (one rule every layout holds a locked node where it is and keeps it in the layout's structure; force treats it as an obstacle its settle separates the others from)
ele.locked(): boolean

Whether the first element is locked — immovable, by layouts, position writes and position tweens alike (one rule every layout holds a locked node where it is and keeps it in the layout's structure; force treats it as an obstacle its settle separates the others from). A locked child stays where it is when its compound parent is positioned, shifted or dragged — its own subtree with it — and the parent re-derives about the stayers and the movers. True for every node while cy.autolock( true) is set; the flag column alone is what { locked: true } filters read.

Returns boolean

true when locked

Example

console.log(eles.locked()); // false

Example graph and handle setup

#eles.lock()

// Lock these elements against movement
eles.lock(): this

Lock these elements against movement. A node locked mid-tween holds where its position tween got to; the rest of the animation — other nodes, and this node's paint channels — runs on, and unlocking does not resume it.

Returns this

this collection, for chaining

Example

const node = cy.getElementById('a');
node.lock();
console.log(node.locked()); // true

Example graph and handle setup

#eles.unlock()

// Unlock these elements
eles.unlock(): this

Unlock these elements.

Returns this

this collection, for chaining

Example

const node = cy.getElementById('a');
node.unlock();
console.log(node.locked()); // false

Example graph and handle setup

#ele.active()

// Whether the first element is in the transient pressed ("active") state
ele.active(): boolean

Whether the first element is in the transient pressed ("active") state.

Returns boolean

the pressed flag the pointer layer sets while a press is held — transient interaction state, not a persisted property

Example

console.log(eles.active()); // false

Example graph and handle setup

#ele.pannable()

// Whether dragging the first element pans the graph instead of grabbing it
ele.pannable(): boolean

Whether dragging the first element pans the graph instead of grabbing it.

Returns boolean

the raw pannable flag; because pannable overrides grabbable, a true here forces grabbable() false

Example

console.log(eles.pannable()); // false

Example graph and handle setup

#eles.panify()

// Make dragging these elements pan the viewport instead of moving them
eles.panify(): this

Make dragging these elements pan the viewport instead of moving them. Pannable overrides grabbable.

Returns this

this collection, for chaining

Example

const node = cy.getElementById('a');
node.panify();
console.log(node.pannable()); // true

Example graph and handle setup

#eles.unpanify()

// Stop these elements from panning the viewport when dragged, so a grabbable one becomes draggable again
eles.unpanify(): this

Stop these elements from panning the viewport when dragged, so a grabbable one becomes draggable again.

Returns this

this collection, for chaining

Example

const node = cy.getElementById('a');
node.unpanify();
console.log(node.pannable()); // false

Example graph and handle setup

All guides · Alphabetical API index · Read continuously