context-menu-demo/src/index.js

29 lines
810 B
JavaScript
Raw Permalink Normal View History

2020-04-17 14:49:19 +02:00
import { makeDragable } from './dragable.js'
import { alignChild } from './context.js'
import { optionsListener, getOptions } from './options.js'
const parent = document.getElementById('parent')
const context = document.getElementById('context')
const container = document.getElementById('container')
makeDragable(parent)
let options = getOptions()
function render() {
const { alignments, boxSizes, containment } = options
parent.style.width = boxSizes.parentWidth
parent.style.height = boxSizes.parentHeight
context.style.width = boxSizes.contextWidth
context.style.height = boxSizes.contextHeight
alignChild(parent, context, container, alignments, containment)
}
optionsListener((newOptions) => {
options = newOptions
render()
})
render()
parent.addEventListener('custom-drag', render)