Scalable

Moveable. Scalable

Source:
Scalable indicates whether the target's x and y can be scale of transform.

Members

throttleScale

Source:
throttle of scaleX, scaleY when scale.
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body);

moveable.throttleScale = 0.1;

scalable

Source:
Default Value:
  • false
Whether or not target can scaled.
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body);

moveable.scalable = true;

renderDirections

Source:
Set directions to show the control box. (default: ["n", "nw", "ne", "s", "se", "sw", "e", "w"])
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, {
    scalable: true,
  renderDirections: ["n", "nw", "ne", "s", "se", "sw", "e", "w"],
});

moveable.renderDirections = ["nw", "ne", "sw", "se"];

keepRatio

Source:
When resize or scale, keeps a ratio of the width, height. (default: false)
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, {
    scalable: true,
});

moveable.keepRatio = true;

Methods

request(e) → {Moveable.Requester}

Source:
Name Type Description
e Moveable.Scalable.ScalableRequestParam the Scalable's request parameter
Example
// Instantly Request (requestStart - request - requestEnd)
moveable.request("scalable", { deltaWidth: 10, deltaHeight: 10 }, true);

// requestStart
const requester = moveable.request("scalable");

// request
requester.request({ deltaWidth: 10, deltaHeight: 10 });
requester.request({ deltaWidth: 10, deltaHeight: 10 });
requester.request({ deltaWidth: 10, deltaHeight: 10 });

// requestEnd
requester.requestEnd();
Returns:
Moveable Requester
Type
Moveable.Requester

Type Definitions

OnBeforeScale

Source:
Properties:
currentTarget: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
moveable: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
target: HTMLElement | SVGElement
The Moveable's target
clientX: number
The horizontal coordinate within the application's client area at which the event occurred.
clientY: number
The vertical coordinate within the application's client area at which the event occurred.
isFirstDrag: number
Whether this is the first drag in the drag event
datas: IObject<any>
Objects that can send information to the following events.
inputEvent: any
The mouse or touch input event that is invoking the moveable event
stopAble: () => void
Stop the currently working able.
stopDrag: () => void
Calling `stopDrag` in a drag-related event ends the drag.
isTrusted: boolean
Whether the event did not occur externally
setFixedDirection: (startDirecition: number[]) => number[]
Set a fixed direction to scale. If fixedDirection is set, the scale values can be changed and can be reconfirmed as a return value.
startFixedDirection: number[]
fixedDirection set by rotateStart.
setScale: (scale: number[]) => void
Set target's scale to scaling.
scale: number[]
a target's scale before snap and throttle and format
Type:
  • TSInterface

OnBeforeScaleGroup

Source:
Properties:
targets: Array<HTMLElement | SVGElement>
The scaling targets
Type:
  • TSInterface

OnScale

Source:
Properties:
style: Record<string, string>
You can get the style you can get from the event.
cssText: string
You can get it as a cssText that you can get from that event.
transform: string
a target's next transform string value.
afterTransform: string
A transform obtained by the simultaneous occurrence of other events in the current event
drag: OnDrag
transform events causes a `drag` event. In some events, there may be no value.
currentTarget: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
moveable: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
target: HTMLElement | SVGElement
The Moveable's target
clientX: number
The horizontal coordinate within the application's client area at which the event occurred.
clientY: number
The vertical coordinate within the application's client area at which the event occurred.
isFirstDrag: number
Whether this is the first drag in the drag event
datas: IObject<any>
Objects that can send information to the following events.
inputEvent: any
The mouse or touch input event that is invoking the moveable event
stopAble: () => void
Stop the currently working able.
stopDrag: () => void
Calling `stopDrag` in a drag-related event ends the drag.
isTrusted: boolean
Whether the event did not occur externally
direction: number[]
The direction of scale.
offsetWidth: number
a target's offsetWidth
offsetHeight: number
a target's offsetHeight
scale: number[]
a target's scale
dist: number[]
The distance of scale
delta: number[]
The delta of scale
isPinch: boolean
Whether or not it is being pinched.
Type:
  • TSInterface

OnScaleEnd

Source:
Properties:
currentTarget: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
moveable: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
target: HTMLElement | SVGElement
The Moveable's target
clientX: number
The horizontal coordinate within the application's client area at which the event occurred.
clientY: number
The vertical coordinate within the application's client area at which the event occurred.
isFirstDrag: number
Whether this is the first drag in the drag event
datas: IObject<any>
Objects that can send information to the following events.
inputEvent: any
The mouse or touch input event that is invoking the moveable event
stopAble: () => void
Stop the currently working able.
stopDrag: () => void
Calling `stopDrag` in a drag-related event ends the drag.
isTrusted: boolean
Whether the event did not occur externally
lastEvent: any | undefined
This is the last dragged event. No, if you haven't dragged.
isDrag: boolean
Whether this moved
isDouble: boolean
Whether it is double-click
Type:
  • TSInterface

OnScaleGroup

Source:
Properties:
targets: Array<HTMLElement | SVGElement>
The scaling targets
events: OnScale[]
Each `scale` & `drag` event on the targets
Type:
  • TSInterface

OnScaleGroupEnd

Source:
Properties:
targets: Array<HTMLElement | SVGElement>
The scale finished targets
events: OnScaleEnd[]
Each `scaleEnd` event on the targets
Type:
  • TSInterface

OnScaleGroupStart

Source:
Properties:
targets: Array<HTMLElement | SVGElement>
targets to scale
events: OnScaleStart[]
Each `scaleStart` & `dragStart` event on the targets
Type:
  • TSInterface

OnScaleStart

Source:
Properties:
Default Value: transform of target's inline style
setTransform: (transform: string | string[], transformIndex?: number) => void
Set your original transform. `transformIndex` is the sequence of functions used in the event. If you use `setTransform`, you don't need to use `set` function.
Default Value: index with that property in transform or last
setTransformIndex: (transformIndex: number) => void
`transformIndex` is the sequence of functions used in the event.
currentTarget: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
moveable: MoveableManagerInterface<Record<string, any>, Record<string, any>>
The Moveable instance
target: HTMLElement | SVGElement
The Moveable's target
clientX: number
The horizontal coordinate within the application's client area at which the event occurred.
clientY: number
The vertical coordinate within the application's client area at which the event occurred.
isFirstDrag: number
Whether this is the first drag in the drag event
datas: IObject<any>
Objects that can send information to the following events.
inputEvent: any
The mouse or touch input event that is invoking the moveable event
stopAble: () => void
Stop the currently working able.
stopDrag: () => void
Calling `stopDrag` in a drag-related event ends the drag.
isTrusted: boolean
Whether the event did not occur externally
direction: number[]
The direction of scale.
dragStart: OnDragStart | false
scale causes a `dragStart` event.
set
set: (scale: number[]) => void
You can set the start scale value.
Default Value: Opposite direction
setFixedDirection: (startDirecition: number[]) => void
Set a fixed direction to scale.
Default Value: offsetWidth / offsetHeight
setRatio: (ratio: number) => void
Set the ratio of width and height.
Default Value: [-Infinity, -Infinity]
setMinScaleSize: (min: number[]) => void
You can set the min scale width, height value. scale size = scale value * offset size
Default Value: [Infinity, Infinity]
setMaxScaleSize: (max: number[]) => void
You can set the max scale width, height value. scale size = scale value * offset size
Type:
  • TSInterface

ScalableOptions

Source:
Properties:
renderDirections optional
Default Value: false if rotatable, ["n", "nw", "ne", "s", "se", "sw", "e", "w"] otherwise
renderDirections?: boolean | string[]
Set directions to show the control box.
edge optional
Default Value: false
edge?: boolean | Array<LineDirection>
Whether to scale and resize through edge lines. You can use "n", "w", "s", "e" in LineDirection array.
Since: 0.44.0
Story Example: options--options-control-padding
Default Value: false
displayAroundControls?: boolean
You can expand the area around the control. Either `rotateAroundControls` or `displayAroundControls` can be used. You can set the area through the `controlPadding` value.
scalable optional
Default Value: false
scalable?: boolean | ScalableOptions
Whether or not target can be scaled.
throttleScale optional
Default Value: 0
throttleScale?: number
throttle of scaleX, scaleY when scale.
keepRatio optional
Default Value: false
keepRatio?: boolean
When resize or scale, keeps a ratio of the width, height.
edge optional
Default Value: false
edge?: boolean | Array<LineDirection>
Whether to scale and resize through edge lines. You can use "n", "w", "s", "e" in LineDirection array.
Type:
  • TSInterface

ScalableRequestParam

Source:
Properties:
isInstant optional
isInstant?: boolean
Run the request instantly. (requestStart, request, requestEnd happen at the same time)
[key: string]: any
direction optional
Default Value: [1, 1]
direction?: number[]
Direction to scale
keepRatio optional
keepRatio?: boolean
Whether to force keepRatio to resize
deltaWidth optional
deltaWidth?: number
delta number of width
deltaHeight optional
deltaHeight?: number
delta number of height
useSnap optional
useSnap?: boolean
whether to use with `snappable`
the Scalable's request parameter
Type:
  • TSInterface

Events

beforeScale

Source:
When scaling, `beforeScale` is called before `scale` occurs. In `beforeScale`, you can get and set the pre-value before scaling.
Type Description
Moveable.Scalable.OnBeforeScale Parameters for the `beforeScale` event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, { scalable: true });
moveable.on("beforeScale", ({ setFixedDirection }) => {
    if (shiftKey) {
       setFixedDirection([0, 0]);
    }
});
moveable.on("scale", ({ target, transform, dist }) => {
    target.style.transform = transform;
});

scale

Source:
When scaling, the `scale` event is called.
Type Description
Moveable.Scalable.OnScale Parameters for the `scale` event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, { scalable: true });
moveable.on("scale", ({ target, transform, dist }) => {
    target.style.transform = transform;
});

scaleEnd

Source:
When the scale finishes, the `scaleEnd` event is called.
Type Description
Moveable.Scalable.OnScaleEnd Parameters for the `scaleEnd` event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, { scalable: true });
moveable.on("scaleEnd", ({ target, isDrag }) => {
    console.log(target, isDrag);
});

scaleGroup

Source:
When the group scale, the `scaleGroup` event is called.
Type Description
Moveable.Scalable.OnScaleGroup Parameters for the `scaleGroup` event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, {
    target: [].slice.call(document.querySelectorAll(".target")),
    scalable: true
});
moveable.on("scaleGroup", ({ targets, events }) => {
    console.log("onScaleGroup", targets);
    events.forEach(ev => {
        const target = ev.target;
        // ev.drag is a drag event that occurs when the group scale.
        const left = ev.drag.beforeDist[0];
        const top = ev.drag.beforeDist[1];
        const scaleX = ev.scale[0];
        const scaleY = ev.scale[1];
    });
});

scaleGroupEnd

Source:
When the group scale finishes, the `scaleGroupEnd` event is called.
Type Description
Moveable.Scalable.OnScaleGroupEnd Parameters for the `scaleGroupEnd` event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, {
    target: [].slice.call(document.querySelectorAll(".target")),
    scalable: true
});
moveable.on("scaleGroupEnd", ({ targets, isDrag }) => {
    console.log("onScaleGroupEnd", targets, isDrag);
});

scaleGroupStart

Source:
When the group scale starts, the `scaleGroupStart` event is called.
Type Description
Moveable.Scalable.OnScaleGroupStart Parameters for the `scaleGroupStart` event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, {
    target: [].slice.call(document.querySelectorAll(".target")),
    scalable: true
});
moveable.on("scaleGroupStart", ({ targets }) => {
    console.log("onScaleGroupStart", targets);
});

scaleStart

Source:
When the scale starts, the scaleStart event is called.
Type Description
Moveable.Scalable.OnScaleStart Parameters for the scaleStart event
Example
import Moveable from "moveable";

const moveable = new Moveable(document.body, { scalable: true });
moveable.on("scaleStart", ({ target }) => {
    console.log(target);
});