import { DirectiveOptions } from 'vue'; /** * v-position 定位 * @author tanxj */ export const position: DirectiveOptions = { inserted: function (el: any, binding: any) { const value = binding.value; const offsetHeight = el.offsetHeight + 25; const clientHeight = document.body.clientHeight; const availableHeight = clientHeight - value.y; let top = 0; if (availableHeight < offsetHeight) { top = value.y - (offsetHeight - availableHeight); } else { top = value.y; } const left = value.x; el.style.left = left + "px"; el.style.top = top + "px"; } };