补充 utils 注释
This commit is contained in:
parent
dce9ffb4b8
commit
9ff2642547
@ -1,18 +1,39 @@
|
||||
// 获取标签与窗口顶边距离
|
||||
/**
|
||||
* 获取 top 属性值
|
||||
* <p>
|
||||
* @param elem dom
|
||||
* */
|
||||
export function getTop(elem) {
|
||||
return elem.offsetTop + (elem.offsetParent && getTop(elem.offsetParent) || 0);
|
||||
}
|
||||
|
||||
// 获取标签与窗口左边距离
|
||||
/**
|
||||
* 获取 left 属性值
|
||||
* <p>
|
||||
* @param elem dom
|
||||
* */
|
||||
export function getLeft(elem) {
|
||||
return elem.offsetLeft + (elem.offsetParent && getLeft(elem.offsetParent) || 0);
|
||||
}
|
||||
|
||||
// 事件绑定
|
||||
/**
|
||||
* 事件绑定
|
||||
* <p>
|
||||
* @param elem dom
|
||||
* @param events 事件
|
||||
* @param handler 事件回调
|
||||
* */
|
||||
export function on(elem, events, handler) {
|
||||
[].concat(events).forEach(event => elem.addEventListener(event, handler, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单次事件
|
||||
* <p>
|
||||
* @param elem dom
|
||||
* @param events 事件
|
||||
* @param handler 事件回调
|
||||
* */
|
||||
export function once (elem, events, handler) {
|
||||
const listener = function (_this, args) {
|
||||
handler.apply(_this, args)
|
||||
@ -21,7 +42,13 @@ export function once (elem, events, handler) {
|
||||
on(elem, events, listener)
|
||||
}
|
||||
|
||||
// 事件解除
|
||||
/**
|
||||
* 事件解除
|
||||
* <p>
|
||||
* @param elem dom
|
||||
* @param events 事件
|
||||
* @param handler 事件回调
|
||||
* */
|
||||
export function off(elem, events, handler) {
|
||||
[].concat(events).forEach(event => elem.removeEventListener(event, handler, false));
|
||||
}
|
@ -1,20 +1,18 @@
|
||||
|
||||
/**
|
||||
* 随机数
|
||||
* <p>
|
||||
* @param null 无参
|
||||
* */
|
||||
export function S4() {
|
||||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机数
|
||||
* <p>
|
||||
* @param null 无参
|
||||
* */
|
||||
export function guid() {
|
||||
return (
|
||||
S4() +
|
||||
S4() +
|
||||
'-' +
|
||||
S4() +
|
||||
'-' +
|
||||
S4() +
|
||||
'-' +
|
||||
S4() +
|
||||
'-' +
|
||||
S4() +
|
||||
S4() +
|
||||
S4()
|
||||
)
|
||||
}
|
||||
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
|
||||
}
|
@ -4,8 +4,7 @@ import { name } from './package.json'
|
||||
import babel from '@rollup/plugin-babel'
|
||||
import plugins from './example/src/plugin/common-plugins'
|
||||
|
||||
const camelize = (name: string) =>
|
||||
name.replace(/(^|-)(\w)/g, (a, b, c) => c.toUpperCase())
|
||||
const camelize = (name: string) => name.replace(/(^|-)(\w)/g, (a, b, c) => c.toUpperCase());
|
||||
|
||||
export default defineConfig({
|
||||
root: path.resolve(__dirname, 'example'),
|
||||
|
Loading…
Reference in New Issue
Block a user