@wanjunshijie/vue-seamless-scroll 0.1.8

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 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 ADDED
@@ -0,0 +1,141 @@
1
+ # vue-seamless-scroll
2
+
3
+ > github: https://github.com/yelingkong/vue-seamless-scroll
4
+
5
+
6
+
7
+ [Document for vue2](https://github.com/yelingkong/vue-seamless-scroll/tree/vue2#readme)
8
+
9
+
10
+
11
+ ## Install
12
+
13
+ ```shell
14
+ # vue3
15
+ # yarn
16
+ yarn add @wanjunshijie/vue-seamless-scroll@latest --dev
17
+ # npm
18
+ npm i @wanjunshijie/vue-seamless-scroll@latest --save-dev
19
+
20
+ # vue2
21
+ # yarn
22
+ yarn add @wanjunshijie/vue-seamless-scroll@latest-v2 --dev
23
+ # npm
24
+ npm i @wanjunshijie/vue-seamless-scroll@latest-v2 --save-dev
25
+ ```
26
+
27
+
28
+
29
+ ## Use
30
+
31
+ `main.ts`
32
+
33
+ ```ts
34
+ import { createApp } from 'vue'
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
+
43
+
44
+
45
+ `env.d.ts`
46
+
47
+ ```ts
48
+ declare module '@wanjunshijie/vue-seamless-scroll'
49
+ ```
50
+
51
+
52
+
53
+ `App.vue`
54
+
55
+ ```vue
56
+ <template>
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>
61
+ </div>
62
+ </template>
63
+
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
+ ])
86
+ </script>
87
+
88
+ <style scoped>
89
+ .box {
90
+ width: 100%;
91
+ padding-top: 50px;
92
+ display: flex;
93
+ justify-content: center;
94
+ }
95
+
96
+ .list {
97
+ height: 300px;
98
+ overflow: hidden;
99
+ }
100
+
101
+ .list-item {
102
+ width: 500px;
103
+ height: 100px;
104
+ margin-bottom: 20px;
105
+ color: #000;
106
+ font-size: 14px;
107
+ background-color: aliceblue;
108
+ }
109
+ </style>
110
+ ```
111
+
112
+
113
+
114
+ ## Api
115
+
116
+ | 属性 | 说明 | 类型 | 默认值 |
117
+ | ------------- | ---------------------------- | -------------------------------------- | ------ |
118
+ | **direction** | 滚动的方向 | 'top' \| 'bottom' \| 'left' \| 'right' | 'top' |
119
+ | **steep** | 滚动的速率 | number | 0.5 |
120
+ | **roller** | 是否可以使用滚轮滚动 | boolean | true |
121
+ | **distance** | 滚轮滚动的速率 | number | 20 |
122
+ | **data** | 接收异步数据,同步任务可不传 | array | - |
123
+
124
+
125
+
126
+ ## Changelog
127
+
128
+ ### 2026-09-20
129
+
130
+ - 新增移动端 / 平板手指拖动滚动支持(触屏拖拽)
131
+ - 修复在移动端、平板等触屏设备上手指拖动列表无法滚动的问题
132
+ - 在原有滚轮滚动基础上,补充 `touchstart` / `touchmove` / `touchend` 触摸事件:手指按下时暂停自动滚动,拖动时列表实时跟随手指移动,松手后恢复自动滚动
133
+ - 拖动过程中对滚动范围做了边界限制,避免把列表拖出空白区域
134
+ - 通过 `touch-action: none` 防止浏览器手势(页面滚动/缩放)劫持触摸事件
135
+
136
+ ## Tips
137
+
138
+ - 如没有显示请为嵌入的标签设置字体大小
139
+ - 当 `direction` 为 `top` 或 `bottom` 时,要为组件设置高度;当 `direction` 为 `left` 或 `right` 时,要为组件设置宽度
140
+ - reference: [@david-j/vue-j-scroll](https://github.com/DavidJ-0/vue-j-scroll.js)
141
+
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
+ };
@@ -0,0 +1 @@
1
+ (function(i,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i["vue-seamless-scroll"]={},i.Vue))})(this,function(i,e){"use strict";const T={name:"VueSeamlessScroll"},W=e.defineComponent({...T,props:{direction:{default:"top"},steep:{default:.5},roller:{type:Boolean,default:!0},distance:{default:20},data:{}},setup(c){const l=c,t=e.reactive({listWidth:0,listHeight:0,bodyWidth:0,bodyHeight:0,canScroll:!1,isStop:!1,scrollDistance:0,animationFrame:null,touchStartX:0,touchStartY:0,touchStartDistance:0}),a=e.ref(),r=e.ref(),s=e.computed(()=>l.direction==="left"||l.direction==="right");e.watch(()=>l.data,()=>{e.nextTick(()=>{S()})}),e.onMounted(()=>{e.nextTick(()=>{S()})}),e.onUnmounted(()=>{u()});function S(){u(),e.nextTick(()=>{var n,o,f,h;t.listWidth=((n=r.value)==null?void 0:n.clientWidth)||0,t.listHeight=((o=r.value)==null?void 0:o.clientHeight)||0,t.bodyWidth=((f=a.value)==null?void 0:f.clientWidth)||0,t.bodyHeight=((h=a.value)==null?void 0:h.clientHeight)||0,t.scrollDistance=0,m()})}function m(){t.isStop=!1,s.value?y(t.listWidth,t.bodyWidth):y(t.listHeight,t.bodyHeight),t.canScroll&&p()}function p(){if(b(),l.steep==0){D();return}t.animationFrame=window.requestAnimationFrame(()=>{D(),t.isStop||(l.direction==="top"||l.direction==="left"?t.scrollDistance-=l.steep:(l.direction==="bottom"||l.direction==="right")&&(t.scrollDistance+=l.steep),p())})}function u(){t.isStop=!0,b()}function y(n,o){t.canScroll=n&&o?n>o:!1}function D(){s.value?_(t.listWidth,t.bodyWidth):_(t.listHeight,t.bodyHeight)}function _(n,o){let f=Math.abs(t.scrollDistance);if(t.scrollDistance<0){let h=2*n-o;f>h&&(t.scrollDistance=-(n-o))}else t.scrollDistance=-n}function g(){let n="";return s.value?n=`translate(${t.scrollDistance}px, 0)`:n=`translate(0, ${t.scrollDistance}px)`,n}function b(){t.animationFrame&&(cancelAnimationFrame(t.animationFrame),t.animationFrame=null)}function k(){u()}function x(){m()}function M(n){if(n.preventDefault(),!t.canScroll||!l.roller)return;n.deltaY>0?t.scrollDistance-=l.distance:t.scrollDistance+=l.distance,p()}function B(n){u();const o=n.touches[0];o&&(t.touchStartX=o.clientX,t.touchStartY=o.clientY,t.touchStartDistance=t.scrollDistance)}function F(n){if(n.preventDefault(),!t.canScroll)return;const o=n.touches[0];o&&(s.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))))}function H(){m()}return(n,o)=>(e.openBlock(),e.createElementBlock("div",{class:"seamless-list",ref_key:"scrollBody",ref:a,onMouseenter:k,onMouseleave:x,onWheel:M,onTouchstart:B,onTouchmove:F,onTouchend:H,onTouchcancel:H},[e.createElementVNode("div",{class:e.normalizeClass(["seamless-list__body",{"is-horizontal":s.value}]),ref_key:"listBody",ref:r,style:e.normalizeStyle({transform:g()})},[e.renderSlot(n.$slots,"default",{},void 0,!0)],6),t.canScroll?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["seamless-list__body",{"is-horizontal":s.value}]),style:e.normalizeStyle({transform:g()})},[e.renderSlot(n.$slots,"default",{},void 0,!0)],6)):e.createCommentVNode("",!0)],544))}}),d=((c,l)=>{const t=c.__vccOpts||c;for(const[a,r]of l)t[a]=r;return t})(W,[["__scopeId","data-v-9dc5b214"]]);d.install=c=>(c.component(d.name,d),c),i.VueSeamlessScroll=d,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@wanjunshijie/vue-seamless-scroll",
3
+ "private": false,
4
+ "version": "0.1.8",
5
+ "type": "module",
6
+ "author": "wanjunshijie",
7
+ "license": "MIT",
8
+ "description": "A simple vue seamless scroll component.",
9
+ "keywords": [
10
+ "vue",
11
+ "vue3",
12
+ "vite",
13
+ "typescript",
14
+ "scroll"
15
+ ],
16
+ "scripts": {
17
+ "dev": "vite",
18
+ "build": "vue-tsc && vite build",
19
+ "preview": "vite preview",
20
+ "pub": "npm publish --tag latest"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/yelingkong/vue-seamless-scroll.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/yelingkong/vue-seamless-scroll/issues"
28
+ },
29
+ "homepage": "https://github.com/yelingkong/vue-seamless-scroll#readme",
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://registry.npmjs.org"
33
+ },
34
+ "dependencies": {
35
+ "vue": "^3.3.11"
36
+ },
37
+ "devDependencies": {
38
+ "@vitejs/plugin-vue": "^4.5.2",
39
+ "typescript": "^5.2.2",
40
+ "vite": "^5.0.8",
41
+ "vite-plugin-dts": "^3.7.0",
42
+ "vue-tsc": "^1.8.25"
43
+ },
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "main": "dist/vue-seamless-scroll.umd.js",
48
+ "module": "dist/vue-seamless-scroll.es.js",
49
+ "types": "dist/index.d.ts",
50
+ "exports": {
51
+ ".": {
52
+ "import": {
53
+ "default": "./dist/vue-seamless-scroll.es.js",
54
+ "types": "./dist/index.d.ts"
55
+ },
56
+ "require": {
57
+ "default": "./dist/vue-seamless-scroll.umd.js",
58
+ "types": "./dist/index.d.ts"
59
+ }
60
+ },
61
+ "./dist/style.css": "./dist/style.css"
62
+ }
63
+ }