@wanjunshijie/vue-seamless-scroll 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +41 -46
- package/dist/style.css +1 -0
- package/dist/vue-seamless-scroll.es.js +143 -0
- package/dist/vue-seamless-scroll.umd.js +1 -914
- package/package.json +34 -38
- package/dist/demo.html +0 -1
- package/dist/vue-seamless-scroll.common.js +0 -903
- package/dist/vue-seamless-scroll.common.js.map +0 -1
- package/dist/vue-seamless-scroll.umd.js.map +0 -1
- package/dist/vue-seamless-scroll.umd.min.js +0 -2
- package/dist/vue-seamless-scroll.umd.min.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jiang Yingqi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# vue-seamless-scroll
|
|
2
2
|
|
|
3
|
-
> github: https://github.com/yelingkong/vue-seamless-scroll
|
|
3
|
+
> github: https://github.com/yelingkong/vue-seamless-scroll
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
[Document for
|
|
7
|
+
[Document for vue2](https://github.com/yelingkong/vue-seamless-scroll/tree/vue2#readme)
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -28,20 +28,24 @@ npm i @wanjunshijie/vue-seamless-scroll@latest-v2 --save-dev
|
|
|
28
28
|
|
|
29
29
|
## Use
|
|
30
30
|
|
|
31
|
-
`main.
|
|
31
|
+
`main.ts`
|
|
32
32
|
|
|
33
|
-
```
|
|
34
|
-
import
|
|
33
|
+
```ts
|
|
34
|
+
import { createApp } from 'vue'
|
|
35
35
|
import App from './App.vue'
|
|
36
|
+
import { VueSeamlessScroll } from '@wanjunshijie/vue-seamless-scroll'
|
|
37
|
+
|
|
38
|
+
const app = createApp(App)
|
|
39
|
+
app.use(VueSeamlessScroll)
|
|
40
|
+
app.mount('#app')
|
|
41
|
+
```
|
|
42
|
+
|
|
36
43
|
|
|
37
|
-
Vue.config.productionTip = false
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
Vue.use(VueSeamlessScroll)
|
|
45
|
+
`env.d.ts`
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}).$mount('#app')
|
|
47
|
+
```ts
|
|
48
|
+
declare module '@wanjunshijie/vue-seamless-scroll'
|
|
45
49
|
```
|
|
46
50
|
|
|
47
51
|
|
|
@@ -50,48 +54,40 @@ new Vue({
|
|
|
50
54
|
|
|
51
55
|
```vue
|
|
52
56
|
<template>
|
|
53
|
-
<div
|
|
54
|
-
<
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
</vue-seamless-scroll>
|
|
58
|
-
</div>
|
|
57
|
+
<div class="box">
|
|
58
|
+
<vue-seamless-scroll class="list" :data="data" direction="top" :steep="0.5" roller :distance="20">
|
|
59
|
+
<div class="list-item" v-for="item, index in data" :key="index">{{ item.text }}</div>
|
|
60
|
+
</vue-seamless-scroll>
|
|
59
61
|
</div>
|
|
60
62
|
</template>
|
|
61
63
|
|
|
62
|
-
<script>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{ text: 'test' },
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
}
|
|
64
|
+
<script setup lang="ts">
|
|
65
|
+
import { ref } from 'vue'
|
|
66
|
+
|
|
67
|
+
let data = ref([
|
|
68
|
+
{ text: 'test' },
|
|
69
|
+
{ text: 'test' },
|
|
70
|
+
{ text: 'test' },
|
|
71
|
+
{ text: 'test' },
|
|
72
|
+
{ text: 'test' },
|
|
73
|
+
{ text: 'test' },
|
|
74
|
+
{ text: 'test' },
|
|
75
|
+
{ text: 'test' },
|
|
76
|
+
{ text: 'test' },
|
|
77
|
+
{ text: 'test' },
|
|
78
|
+
{ text: 'test' },
|
|
79
|
+
{ text: 'test' },
|
|
80
|
+
{ text: 'test' },
|
|
81
|
+
{ text: 'test' },
|
|
82
|
+
{ text: 'test' },
|
|
83
|
+
{ text: 'test' },
|
|
84
|
+
{ text: 'test' },
|
|
85
|
+
])
|
|
89
86
|
</script>
|
|
90
87
|
|
|
91
88
|
<style scoped>
|
|
92
89
|
.box {
|
|
93
90
|
width: 100%;
|
|
94
|
-
height: 200px;
|
|
95
91
|
padding-top: 50px;
|
|
96
92
|
display: flex;
|
|
97
93
|
justify-content: center;
|
|
@@ -111,7 +107,6 @@ export default {
|
|
|
111
107
|
background-color: aliceblue;
|
|
112
108
|
}
|
|
113
109
|
</style>
|
|
114
|
-
|
|
115
110
|
```
|
|
116
111
|
|
|
117
112
|
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.seamless-list[data-v-9dc5b214]{overflow:hidden;touch-action:none}.seamless-list__body[data-v-9dc5b214]{overflow:hidden}.seamless-list__body.is-horizontal[data-v-9dc5b214]{display:inline-block;font-size:0}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { defineComponent as C, reactive as V, ref as b, computed as $, watch as w, nextTick as h, onMounted as A, onUnmounted as E, openBlock as H, createElementBlock as W, createElementVNode as N, normalizeClass as M, normalizeStyle as T, renderSlot as k, createCommentVNode as q } from "vue";
|
|
2
|
+
const z = {
|
|
3
|
+
name: "VueSeamlessScroll"
|
|
4
|
+
}, I = /* @__PURE__ */ C({
|
|
5
|
+
...z,
|
|
6
|
+
props: {
|
|
7
|
+
direction: { default: "top" },
|
|
8
|
+
steep: { default: 0.5 },
|
|
9
|
+
roller: { type: Boolean, default: !0 },
|
|
10
|
+
distance: { default: 20 },
|
|
11
|
+
data: {}
|
|
12
|
+
},
|
|
13
|
+
setup(l) {
|
|
14
|
+
const n = l, t = V({
|
|
15
|
+
listWidth: 0,
|
|
16
|
+
listHeight: 0,
|
|
17
|
+
bodyWidth: 0,
|
|
18
|
+
bodyHeight: 0,
|
|
19
|
+
canScroll: !1,
|
|
20
|
+
isStop: !1,
|
|
21
|
+
scrollDistance: 0,
|
|
22
|
+
animationFrame: null,
|
|
23
|
+
touchStartX: 0,
|
|
24
|
+
touchStartY: 0,
|
|
25
|
+
touchStartDistance: 0
|
|
26
|
+
}), c = b(), s = b(), i = $(() => n.direction === "left" || n.direction === "right");
|
|
27
|
+
w(() => n.data, () => {
|
|
28
|
+
h(() => {
|
|
29
|
+
D();
|
|
30
|
+
});
|
|
31
|
+
}), A(() => {
|
|
32
|
+
h(() => {
|
|
33
|
+
D();
|
|
34
|
+
});
|
|
35
|
+
}), E(() => {
|
|
36
|
+
a();
|
|
37
|
+
});
|
|
38
|
+
function D() {
|
|
39
|
+
a(), h(() => {
|
|
40
|
+
var e, o, r, u;
|
|
41
|
+
t.listWidth = ((e = s.value) == null ? void 0 : e.clientWidth) || 0, t.listHeight = ((o = s.value) == null ? void 0 : o.clientHeight) || 0, t.bodyWidth = ((r = c.value) == null ? void 0 : r.clientWidth) || 0, t.bodyHeight = ((u = c.value) == null ? void 0 : u.clientHeight) || 0, t.scrollDistance = 0, d();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function d() {
|
|
45
|
+
t.isStop = !1, i.value ? p(t.listWidth, t.bodyWidth) : p(t.listHeight, t.bodyHeight), t.canScroll && f();
|
|
46
|
+
}
|
|
47
|
+
function f() {
|
|
48
|
+
if (g(), n.steep == 0) {
|
|
49
|
+
S();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
t.animationFrame = window.requestAnimationFrame(() => {
|
|
53
|
+
S(), t.isStop || (n.direction === "top" || n.direction === "left" ? t.scrollDistance -= n.steep : (n.direction === "bottom" || n.direction === "right") && (t.scrollDistance += n.steep), f());
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function a() {
|
|
57
|
+
t.isStop = !0, g();
|
|
58
|
+
}
|
|
59
|
+
function p(e, o) {
|
|
60
|
+
t.canScroll = e && o ? e > o : !1;
|
|
61
|
+
}
|
|
62
|
+
function S() {
|
|
63
|
+
i.value ? v(t.listWidth, t.bodyWidth) : v(t.listHeight, t.bodyHeight);
|
|
64
|
+
}
|
|
65
|
+
function v(e, o) {
|
|
66
|
+
let r = Math.abs(t.scrollDistance);
|
|
67
|
+
if (t.scrollDistance < 0) {
|
|
68
|
+
let u = 2 * e - o;
|
|
69
|
+
r > u && (t.scrollDistance = -(e - o));
|
|
70
|
+
} else
|
|
71
|
+
t.scrollDistance = -e;
|
|
72
|
+
}
|
|
73
|
+
function y() {
|
|
74
|
+
let e = "";
|
|
75
|
+
return i.value ? e = `translate(${t.scrollDistance}px, 0)` : e = `translate(0, ${t.scrollDistance}px)`, e;
|
|
76
|
+
}
|
|
77
|
+
function g() {
|
|
78
|
+
t.animationFrame && (cancelAnimationFrame(t.animationFrame), t.animationFrame = null);
|
|
79
|
+
}
|
|
80
|
+
function B() {
|
|
81
|
+
a();
|
|
82
|
+
}
|
|
83
|
+
function F() {
|
|
84
|
+
d();
|
|
85
|
+
}
|
|
86
|
+
function x(e) {
|
|
87
|
+
if (e.preventDefault(), !t.canScroll || !n.roller)
|
|
88
|
+
return;
|
|
89
|
+
e.deltaY > 0 ? t.scrollDistance -= n.distance : t.scrollDistance += n.distance, f();
|
|
90
|
+
}
|
|
91
|
+
function Y(e) {
|
|
92
|
+
a();
|
|
93
|
+
const o = e.touches[0];
|
|
94
|
+
o && (t.touchStartX = o.clientX, t.touchStartY = o.clientY, t.touchStartDistance = t.scrollDistance);
|
|
95
|
+
}
|
|
96
|
+
function X(e) {
|
|
97
|
+
if (e.preventDefault(), !t.canScroll)
|
|
98
|
+
return;
|
|
99
|
+
const o = e.touches[0];
|
|
100
|
+
o && (i.value ? (t.scrollDistance = t.touchStartDistance + o.clientX - t.touchStartX, t.scrollDistance = Math.max(-(t.listWidth - t.bodyWidth), Math.min(0, t.scrollDistance))) : (t.scrollDistance = t.touchStartDistance + o.clientY - t.touchStartY, t.scrollDistance = Math.max(-(t.listHeight - t.bodyHeight), Math.min(0, t.scrollDistance))));
|
|
101
|
+
}
|
|
102
|
+
function _() {
|
|
103
|
+
d();
|
|
104
|
+
}
|
|
105
|
+
return (e, o) => (H(), W("div", {
|
|
106
|
+
class: "seamless-list",
|
|
107
|
+
ref_key: "scrollBody",
|
|
108
|
+
ref: c,
|
|
109
|
+
onMouseenter: B,
|
|
110
|
+
onMouseleave: F,
|
|
111
|
+
onWheel: x,
|
|
112
|
+
onTouchstart: Y,
|
|
113
|
+
onTouchmove: X,
|
|
114
|
+
onTouchend: _,
|
|
115
|
+
onTouchcancel: _
|
|
116
|
+
}, [
|
|
117
|
+
N("div", {
|
|
118
|
+
class: M(["seamless-list__body", { "is-horizontal": i.value }]),
|
|
119
|
+
ref_key: "listBody",
|
|
120
|
+
ref: s,
|
|
121
|
+
style: T({ transform: y() })
|
|
122
|
+
}, [
|
|
123
|
+
k(e.$slots, "default", {}, void 0, !0)
|
|
124
|
+
], 6),
|
|
125
|
+
t.canScroll ? (H(), W("div", {
|
|
126
|
+
key: 0,
|
|
127
|
+
class: M(["seamless-list__body", { "is-horizontal": i.value }]),
|
|
128
|
+
style: T({ transform: y() })
|
|
129
|
+
}, [
|
|
130
|
+
k(e.$slots, "default", {}, void 0, !0)
|
|
131
|
+
], 6)) : q("", !0)
|
|
132
|
+
], 544));
|
|
133
|
+
}
|
|
134
|
+
}), O = (l, n) => {
|
|
135
|
+
const t = l.__vccOpts || l;
|
|
136
|
+
for (const [c, s] of n)
|
|
137
|
+
t[c] = s;
|
|
138
|
+
return t;
|
|
139
|
+
}, m = /* @__PURE__ */ O(I, [["__scopeId", "data-v-9dc5b214"]]);
|
|
140
|
+
m.install = (l) => (l.component(m.name, m), l);
|
|
141
|
+
export {
|
|
142
|
+
m as VueSeamlessScroll
|
|
143
|
+
};
|