# custom-drag-drop

> ## examples ### custom-drag-mixin #### Show header & move element ```html

Latest version **0.2.5** (published 2018-06-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install custom-drag-drop
pnpm add custom-drag-drop
yarn add custom-drag-drop
bun add custom-drag-drop
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2018-06-09 |
| First published | 2018-06-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Glenn Vandeuren |
| Maintainers | vandeurenglenn |
| Keywords | custom, drag, drop |

## Links

- npm: https://www.npmjs.com/package/custom-drag-drop
- Repository: https://github.com/vandeurenglenn/custom-drag-drop
- Homepage: https://github.com/vandeurenglenn/custom-drag-drop#readme
- Issues: https://github.com/vandeurenglenn/custom-drag-drop/issues
- npm.io page: https://npm.io/package/custom-drag-drop

## Recent versions

- 0.2.5 (latest) — 2018-06-09
- 0.2.4 — 2018-06-09
- 0.2.3 — 2018-06-09
- 0.2.2 — 2018-06-09
- 0.2.1 — 2018-06-09
- 0.2.0 — 2018-06-09
- 0.1.1 — 2018-06-09
- 0.1.0 — 2018-06-09

## README

# custom-drag-drop

## examples
### custom-drag-mixin
#### Show header & move element
```html
<custom-example></custom-example>

<script type='module'>
  import CustomDragMixin from '../custom-drag-drop/custom-drag-mixin';
  
  class CustomExample extends CustomDragMixin(HTMLElement) {
    constructor() {
      super();
      this.attachShadow({mode: 'open'});
      this.shadowRoot.innerHTML = `
        <style>
          :host {
            position: absolute;
            display: flex;
            flex-direction: column;
            height: 320px;
            width: 240px;
          }
          header {
            height: 64px;
            width: 100%;
            background: #222;
            color: #fff;
          }
        </style>
        <header class="moving-element">
          Click & Drag
        </header>
        <slot></slot>
      `;
    }
  }
  customElements.define('custom-example', CustomExample);
</script>
```
#### Show header & move parent element
```html
<custom-parent></custom-parent>

<script type='module'>
  import CustomDragMixin from '../custom-drag-drop/custom-drag-mixin';
  class CustomParent extends HTMLElement {
    constructor() {
      super();
      this.attachShadow({mode: 'open'});
      this.shadowRoot.innerHTML = `
        <style>
          :host {
            position: absolute;
            display: flex;
            flex-direction: column;
            height: 320px;
            width: 240px;
          }
          header {
            height: 64px;
            width: 100%;
            background: #222;
            color: #fff;
          }
        </style>
        <custom-child>
          <slot></slot>
        </custom-child>
      `;
    }
  }
  
  class CustomChild extends CustomDragMixin(HTMLElement) {
    constructor() {
      super();
      this.attachShadow({mode: 'open'});
      this.shadowRoot.innerHTML = `
        <style>
          :host {
            display: flex;
            flex-direction: column;
          }
          header {
            height: 64px;
            width: 100%;
            background: #222;
            color: #fff;
          }
        </style>
        
        <header class="moving-element">
          Click & Drag
        </header>
        <slot></slot>
      `;
    }
    moveElement(top, left) {
      top = `${this.parentNode.host.offsetTop - top}px`;
      left = `${this.parentNode.host.offsetLeft - left}px`;

      this.parentNode.host.style.position = 'absolute';
      this.parentNode.host.style.top = top;
      this.parentNode.host.style.left = left;
    }
  }
  
  customElements.define('custom-child', CustomChild);
  customElements.define('custom-parent', CustomParent);
</script>
```

---
_Source: https://npm.io/package/custom-drag-drop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
