A custom element for cropping a square image. Returns x, y, width, and height.
Перейти к файлу
Keith Cirkel b496c92994
4.0.0
2020-11-05 12:11:35 +00:00
.github/workflows Build on all pushes 2020-05-20 15:38:44 -04:00
examples Convert to TypeScript 2020-05-20 15:29:39 -04:00
src Add back HTMLElementTagNameMap 2020-05-22 17:38:01 -04:00
test Remove network requirement from test 2020-05-20 17:03:01 -04:00
.eslintrc.json Convert to TypeScript 2020-05-20 15:29:39 -04:00
.gitignore Ignore build files 2017-11-16 16:08:15 +08:00
CODEOWNERS Create CODEOWNERS 2020-05-20 17:19:22 -04:00
LICENSE Update license 2018-06-22 14:39:12 -07:00
package-lock.json 4.0.0 2020-11-05 12:11:35 +00:00
package.json 4.0.0 2020-11-05 12:11:35 +00:00
readme.md add browser support section 2019-02-25 13:56:32 +00:00
tsconfig.json Convert to TypeScript 2020-05-20 15:29:39 -04:00

readme.md

<image-crop-element>

This loads an image and creates a crop area that user can modify. An event is fired with x, y, width, and height as the crop area changes.

Installation

$ npm install --save @github/image-crop-element

Usage

Plain

<image-crop src="/avatar.jpg"></image-crop>

With loading state

<image-crop src="/avatar.jpg">
  <img src="spinner.gif" alt="" data-loading-slot>
</image-crop>

With autoupdate inputs

<image-crop src="/avatar.jpg">
  <input type="hidden" data-image-crop-input="x" name="x">
  <input type="hidden" data-image-crop-input="y" name="y">
  <input type="hidden" data-image-crop-input="width" name="width">
  <input type="hidden" data-image-crop-input="height" name="height">
</image-crop>

Listen to the change event

document.addEventListener('image-crop-change', function (event){
  console.log(
    'Crop area changed.',
    event.detail.x,
    event.detail.y,
    event.detail.width,
    event.detail.height
  )
})

Browser support

Browsers without native custom element support require a polyfill. Legacy browsers require various other polyfills. See examples/index.html for details.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge