docs/api/cropper-canvas.md
The CropperCanvas interface provides properties and methods for manipulating the layout and presentation of <cropper-canvas> elements.
:::live-demo
<cropper-canvas></cropper-canvas>
:::
:::tip
The default minimum width and minimum height of this element are 200px and 100px.
:::
:::live-demo
<cropper-canvas background></cropper-canvas>
:::
:::live-demo
<cropper-canvas background>
<cropper-image src="/cropperjs/picture.jpg" alt="Picture" rotatable scalable skewable translatable></cropper-image>
<cropper-handle action="move" plain></cropper-handle>
</cropper-canvas>
:::
All pointer events are disabled.
:::live-demo
<cropper-canvas background disabled>
<cropper-image src="/cropperjs/picture.jpg" alt="Picture" rotatable scalable skewable translatable></cropper-image>
<cropper-handle action="move" plain></cropper-handle>
</cropper-canvas>
:::
Inherits properties from its parent, CropperElement, and implements the following properties:
| Name | Type | Default | Options | Description |
|---|---|---|---|---|
| background | boolean | false | - | Indicates whether this element has a grid background. |
| disabled | boolean | false | - | Indicates whether this element is disabled. |
| scaleStep | number | 0.1 | - | Indicates the stepping interval of the scaling factor when zooming in/out by wheeling, must a positive number. |
| themeColor | string | "#39f" | - | Indicates the primary color of this element and its children. |
$setAction(action)action:
stringCropperCanvasChanges the current action to a new one.
$toCanvas()$toCanvas(options)options:
Objectwidth:
numberheight:
numberbeforeDraw:
FunctionbeforeDraw(context, canvas)context:
CanvasRenderingContext2Dcanvas:
HTMLCanvasElementfunction (context) { context.filter = 'grayscale(100%)'; }PromiseGenerates a real canvas element, with the image drawn into if there is one.
The event is fired when a pointer changes on the canvas.
truefalsetrueObjectstring"select", "move", "scale", "rotate", "transform", "n-resize", "e-resize", "s-resize", "w-resize", "ne-resize", "nw-resize", "se-resize", and "sw-resize".PointerEvent | TouchEvent | MouseEvent | WheelEventnumberaction is "scale" or "transform".numberaction is "rotate"or "transform".numberpageX value, only available when the relatedEvent is PointerEvent, TouchEvent, or MouseEvent.numberpageY value, only available when the relatedEvent is PointerEvent, TouchEvent, or MouseEvent.numberpageX value, only available when the relatedEvent is PointerEvent, TouchEvent, or MouseEvent.numberpageY value, only available when the relatedEvent is PointerEvent, TouchEvent, or MouseEvent.<cropper-canvas id="canvas"></cropper-canvas>
<script>
document.querySelector('#canvas').addEventListener('action', function (event) {
console.log(event);
});
</script>
The event is fired when a pointer becomes active.
truetruetrueObjectstringaction event, except for the "scale" option.PointerEvent | TouchEvent | MouseEventThis event is fired when a pointer changes coordinates.
truetruetrueObjectstringaction event, except for the "scale" option.PointerEvent | TouchEvent | MouseEventThis event is fired when a pointer is no longer active.
truetruetrueObjectstringaction event, except for the "scale" option.PointerEvent | TouchEvent | MouseEventThere is only one default slot in this element.
You can disable it by setting the
slottableproperty tofalse:html<cropper-canvas slottable="false"></cropper-canvas>