Skip to content

Commit 23c0eb1

Browse files
author
Simon he
committed
chore: add isMap
1 parent 8e686ae commit 23c0eb1

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,21 @@ getDevice() => { os: 'android', dev: 'chrome' }
295295
preload('https://img.yzcdn.cn/vant/cat.jpeg')
296296
preload(['https://img.yzcdn.cn/vant/cat.jpeg', 'https://img.yzcdn.cn/vant/dog.jpeg'])
297297
```
298+
## lazyLoad
299+
- 图片懒加载
300+
- params-1: 图片的集合 Element | Element[] | NodeList[] | class | id | tagName
301+
- params-2: root 指定相对容器默认是body
302+
- params-3: rootMargin 指定相对容器的边距 默认距离容器底部200px时候加载(↑ → ↓ ←) '0px 0px 200px 0px'
303+
- params-4: threshold 指定图片加载的阈值
304+
```javascript
305+
// usage
306+
lazyLoad(document.querySelectorAll("img"));
307+
lazyLoad("img[data-src]");
308+
lazyLoad(".img-wrapper>img");
309+
// template
310+
<img src="temp" data-src="../public/favicon.svg" alt="" h-10 bg-red />
298311

312+
```
299313
## addScript
300314
- 动态添加script标签
301315
```javascript
@@ -444,6 +458,23 @@ formateNum(number: number | string, decimals = 2, integer: 'floor' | 'ceil' = 'c
444458
interceptError(fn: Function) => Promise<any>
445459
```
446460
461+
## isBottom
462+
- 判断滚动是否触底
463+
- distance: 距离底部的距离作为触底的判断标准 默认0
464+
```javascript
465+
isBottom(distance: string = 0) => boolean
466+
```
467+
468+
## calNum
469+
- 计算数字
470+
- type: '' | '' | '' | ''
471+
```javascript
472+
console.log(calNum.add(0.1, 0.2, 0.2)) => 0.5
473+
console.log(calNum.div(0.1, 0.2, 0.2)) => 2.5
474+
console.log(calNum.sub(0.1, 0.2, 0.2)) => -0.3
475+
console.log(calNum.mul(0.1, 0.2, 0.2)) => 0.004
476+
```
477+
447478
## 类型判断
448479
- isArray(obj) - 判断是否是数组
449480
- isPlainObject(obj) - 判断是否是纯对象

playground/src/App.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
// import { lazyLoad } from "../../src";
23
// import { vFetch } from "../../src";
34
45
// setTimeout(() => {
@@ -9,11 +10,21 @@
910
// return res;
1011
// });
1112
// }, 2000);
13+
// onMounted(() => {
14+
// lazyLoad(document.querySelectorAll("img"));
15+
// lazyLoad("img[data-src]");
16+
// lazyLoad(".img-wrapper>img");
17+
// // document.querySelectorAll("img").forEach((img) => {
18+
// // lazyLoad(img);
19+
// // });
20+
// });
1221
</script>
1322

1423
<template>
15-
<main font-sans p="x-4 y-10" text="center gray-700 dark:gray-200">
24+
<main font-sans p="x-4 y-10" text="center gray-700 dark:gray-200" h-1000>
1625
<router-view />
1726
<Footer />
1827
</main>
28+
<!-- <img src="temp" data-src="../public/favicon.svg" alt="" h-10 bg-red /> -->
29+
<!-- <img src="temp" alt="" h-10 bg-red /> -->
1930
</template>

playground/src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createApp } from 'vue'
22
import { createRouter, createWebHistory } from 'vue-router'
33
import routes from 'virtual:generated-pages'
4-
import { monitorPef, vFetch } from '../../src'
4+
import { monitorPef, vFetch, calNum, lazyLoad } from '../../src'
55
import App from './App.vue'
66

77
import '@unocss/reset/tailwind.css'
@@ -34,6 +34,9 @@ instance({
3434
return res
3535
})
3636
monitorPef()
37+
console.log(calNum.sub(0.1, 0.2, 0.2))
38+
console.log(calNum.mul(0.1, 0.2, 0.2))
39+
3740
// console.log(formateNum(123456789.123456789, 3, 'floor'))
3841
// console.log(uppercaseNum(-122.12))
3942
// console.log(trim(' g xx ', 'all').length)

playground/src/styles/main.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
html,
22
body,
33
#app {
4-
height: 100%;
54
margin: 0;
65
padding: 0;
76
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ export { base64ToFile } from './base64ToFile'
6161
export { base64ToBlob } from './base64ToBlob'
6262
export { uppercaseNum } from './uppercaseNum'
6363
export { formateNum } from './formateNum'
64+
export { isBottom } from './isBottom'
65+
export { calNum } from './calNum'
66+
export { lazyLoad } from './lazyLoad'

src/isMap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { _toString } from './common';
2+
export function isMap(o: any) {
3+
return _toString.call(o) === '[object Map]';
4+
}

0 commit comments

Comments
 (0)