Skip to content

Commit 8dc0595

Browse files
committed
fix: fix dirs bug
1 parent 53aae30 commit 8dc0595

File tree

8 files changed

+34
-73
lines changed

8 files changed

+34
-73
lines changed

.github/workflows/test.yml renamed to .github/workflows/prebuild.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test
1+
name: Prebuild
22

33
on:
44
push:
@@ -37,3 +37,6 @@ jobs:
3737
- name: Build
3838
run: pnpm run build
3939

40+
- name: Build Docs
41+
run: pnpm run docs:build
42+

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import DefaultTheme from 'vitepress/theme'
44
import './style.css'
55

66
import VueDirectives from '../../../src'
7+
78
export default {
89
extends: DefaultTheme,
910
enhanceApp({ app }) {

docs/en/api-examples.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

docs/en/directives/.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/en/directives/v-tooltip.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Adding Tooltips to Elements
1010
import { ref } from 'vue'
1111

1212
const show = ref('Reminder 2')
13+
const count = ref(0)
1314
</script>
1415

1516
<div :style="{
@@ -41,6 +42,7 @@ const show = ref('Reminder 2')
4142
import { ref } from 'vue'
4243

4344
const show = ref('Reminder 2')
45+
const count = ref(0)
4446
</script>
4547

4648
<template>

docs/zh/directives/v-tooltip.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import { ref } from 'vue'
1111

1212
const show = ref('提示信息2')
13+
const count = ref(0)
1314
</script>
1415

1516
<div :style="{
@@ -41,6 +42,7 @@ const show = ref('提示信息2')
4142
import { ref } from 'vue'
4243

4344
const show = ref('提示信息2')
45+
const count = ref(0)
4446
</script>
4547

4648
<template>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@ileostar/v3-directives",
3+
"type": "module",
34
"version": "0.0.5",
45
"packageManager": "[email protected]",
5-
"type": "module",
66
"description": "Custom Vue3 directives",
77
"author": "ileostar <[email protected]> (https://github.com/ileostar)",
88
"license": "MIT",
@@ -15,17 +15,17 @@
1515
"directives",
1616
"vue3"
1717
],
18-
"main": "dist/index.js",
1918
"exports": {
2019
".": {
2120
"import": "./dist/index.mjs",
2221
"require": "./dist/index.js"
2322
}
2423
},
24+
"main": "dist/index.js",
25+
"types": "dist/index.d.ts",
2526
"files": [
2627
"dist"
2728
],
28-
"types": "dist/index.d.ts",
2929
"scripts": {
3030
"build": "tsup",
3131
"dev": "tsup --watch & eslint-flat-config-viewer",

src/directive/v-slideIn/index.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@ const ANIMATIONTIME = 500 // 500毫秒
55
let distance: number | null = null
66
let animationtime: number | null = null
77
const map = new WeakMap()
8-
const ob = new IntersectionObserver((entries) => {
9-
for (const entrie of entries) {
10-
if (entrie.isIntersecting) {
11-
const animation = map.get(entrie.target)
12-
if (animation) {
13-
animation.play()
14-
ob.unobserve(entrie.target)
15-
}
16-
}
17-
}
18-
})
8+
199
function isBelowViewport(el: HTMLElement) {
2010
const rect = el.getBoundingClientRect()
2111
return rect.top - (distance || DISTANCE) > window.innerHeight
2212
}
2313

14+
function handleScroll() {
15+
const elements = document.querySelectorAll('[v-slide-in]')
16+
elements.forEach((el: any) => {
17+
if (isBelowViewport(el)) return
18+
19+
const animation = map.get(el)
20+
if (animation) {
21+
animation.play()
22+
el.removeAttribute('v-slide-in')
23+
}
24+
})
25+
}
26+
2427
const vSlideIn: Directive = {
2528
mounted(el: HTMLElement, binding: any) {
26-
if (binding.value) { // 传值?
27-
console.log(binding.value)// 打印
28-
distance = binding.value.px// 接收指定距离
29-
animationtime = binding.value.time// 接收指定时间
29+
if (binding.value) {
30+
distance = binding.value.px // 接收指定距离
31+
animationtime = binding.value.time // 接收指定时间
3032
}
3133
if (!isBelowViewport(el))
3234
return
@@ -50,11 +52,14 @@ const vSlideIn: Directive = {
5052
)
5153
animation.pause()
5254
map.set(el, animation)
53-
ob.observe(el)
55+
el.setAttribute('v-slide-in', '') // 添加标记,表示需要进行动画
56+
57+
window.addEventListener('scroll', handleScroll)
5458
},
5559

5660
unmounted(el: HTMLElement) {
57-
ob.unobserve(el)
61+
map.delete(el)
62+
window.removeEventListener('scroll', handleScroll)
5863
},
5964
}
6065

0 commit comments

Comments
 (0)