快捷定位

This commit is contained in:
satori 2024-08-26 01:00:32 +08:00
parent 573e40f4e2
commit b094b3f914
2 changed files with 34 additions and 2 deletions

View File

@ -1,6 +1,22 @@
import { div, span, pre, h1, p, ul, li, button } from './main.js' import { div, span, pre, h1, p, ul, li, button, createElement } from './main.js'
import { Dialog } from './wigets/dialog.js' import { Dialog } from './wigets/dialog.js'
// 会话/账户
document.body.appendChild(createElement({
style: {
position: 'fixed',
top: 0,
right: 0,
},
children: [
div.text('session')
]
}))
document.body.appendChild(div.fixed.t_2.r_2.bg_red_500.childs([
div.text('session-x')
]))
// 动画三阶段 // 动画三阶段
// 1. 初始状态 // 1. 初始状态
// 2. 变化过程 // 2. 变化过程

18
main.js
View File

@ -51,7 +51,13 @@ export function createElement({ innerText, innerHTML, textContent, readOnly, chi
'px': ['paddingLeft', 'paddingRight'], 'px': ['paddingLeft', 'paddingRight'],
'py': ['paddingTop', 'paddingBottom'], 'py': ['paddingTop', 'paddingBottom'],
'mx': ['marginLeft', 'marginRight'], 'mx': ['marginLeft', 'marginRight'],
'my': ['marginTop', 'marginBottom'] 'my': ['marginTop', 'marginBottom'],
't': ['top'],
'b': ['bottom'],
'l': ['left'],
'r': ['right'],
'x': ['left', 'right'],
'y': ['top', 'bottom']
} }
if (styleMap.hasOwnProperty(key)) { if (styleMap.hasOwnProperty(key)) {
@ -61,6 +67,16 @@ export function createElement({ innerText, innerHTML, textContent, readOnly, chi
return return
} }
// 支持快捷定位 position
if (['static', 'fixed', 'absolute', 'relative', 'sticky'].includes(key)) {
element.style.position = key
}
// 支持快捷布局 display
if (['block', 'inline-block', 'flex', 'grid'].includes(key)) {
element.style.display = key
}
// TODO 支持颜色输入 // TODO 支持颜色输入
if (key === 'color') { if (key === 'color') {
element.style.color = value element.style.color = value