mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
fix: reset xPos and yPos in seamlessScroll
This commit is contained in:
parent
e09ed0fb47
commit
f886a38694
@ -30,7 +30,7 @@ import {
|
|||||||
ref,
|
ref,
|
||||||
unref,
|
unref,
|
||||||
watchEffect,
|
watchEffect,
|
||||||
nextTick,
|
nextTick
|
||||||
} from "vue";
|
} from "vue";
|
||||||
import { tryOnMounted, tryOnUnmounted, templateRef } from "@vueuse/core";
|
import { tryOnMounted, tryOnUnmounted, templateRef } from "@vueuse/core";
|
||||||
import * as utilsMethods from "./utils";
|
import * as utilsMethods from "./utils";
|
||||||
@ -56,14 +56,14 @@ export default defineComponent({
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => {
|
default: () => {
|
||||||
return [];
|
return [];
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
classOption: {
|
classOption: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {
|
default: () => {
|
||||||
return {};
|
return {};
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
emits: ["ScrollEnd"],
|
emits: ["ScrollEnd"],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
@ -117,7 +117,7 @@ export default defineComponent({
|
|||||||
switchDelay: 400,
|
switchDelay: 400,
|
||||||
switchDisabledClass: "disabled",
|
switchDisabledClass: "disabled",
|
||||||
// singleWidth/singleHeight 是否开启rem度量
|
// singleWidth/singleHeight 是否开启rem度量
|
||||||
isSingleRemUnit: false,
|
isSingleRemUnit: false
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -138,17 +138,16 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
margin: `${unref(height) / 2}px 0 0 -${unref(options).switchOffset}px`,
|
margin: `${unref(height) / 2}px 0 0 -${unref(options).switchOffset}px`,
|
||||||
transform: "translate(-100%,-50%)",
|
transform: "translate(-100%,-50%)"
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let rightSwitch = computed(() => {
|
let rightSwitch = computed(() => {
|
||||||
return {
|
return {
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
margin: `${unref(height) / 2}px 0 0 ${
|
margin: `${unref(height) / 2}px 0 0 ${unref(width) +
|
||||||
unref(width) + unref(options).switchOffset
|
unref(options).switchOffset}px`,
|
||||||
}px`,
|
transform: "translateY(-50%)"
|
||||||
transform: "translateY(-50%)",
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -169,7 +168,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
transform: `translate(${unref(xPos)}px,${unref(yPos)}px)`,
|
transform: `translate(${unref(xPos)}px,${unref(yPos)}px)`,
|
||||||
transition: `all ${ease} ${unref(delay)}ms`,
|
transition: `all ${ease} ${unref(delay)}ms`,
|
||||||
overflow: "hidden",
|
overflow: "hidden"
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -225,6 +224,8 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
|
xPos.value = 0;
|
||||||
|
yPos.value = 0;
|
||||||
scrollCancle();
|
scrollCancle();
|
||||||
scrollInitMove();
|
scrollInitMove();
|
||||||
}
|
}
|
||||||
@ -265,7 +266,7 @@ export default defineComponent({
|
|||||||
//取第一个touch的坐标值
|
//取第一个touch的坐标值
|
||||||
startPos = {
|
startPos = {
|
||||||
x: touch.pageX,
|
x: touch.pageX,
|
||||||
y: touch.pageY,
|
y: touch.pageY
|
||||||
};
|
};
|
||||||
//记录touchStart时候的posY
|
//记录touchStart时候的posY
|
||||||
startPosY = unref(yPos);
|
startPosY = unref(yPos);
|
||||||
@ -293,7 +294,7 @@ export default defineComponent({
|
|||||||
const { direction } = unref(options);
|
const { direction } = unref(options);
|
||||||
let endPos = {
|
let endPos = {
|
||||||
x: touch.pageX - startPos.x,
|
x: touch.pageX - startPos.x,
|
||||||
y: touch.pageY - startPos.y,
|
y: touch.pageY - startPos.y
|
||||||
};
|
};
|
||||||
//阻止触摸事件的默认行为,即阻止滚屏
|
//阻止触摸事件的默认行为,即阻止滚屏
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -350,7 +351,7 @@ export default defineComponent({
|
|||||||
if (isHover) return;
|
if (isHover) return;
|
||||||
//进入move立即先清除动画 防止频繁touchMove导致多动画同时进行
|
//进入move立即先清除动画 防止频繁touchMove导致多动画同时进行
|
||||||
scrollCancle();
|
scrollCancle();
|
||||||
reqFrame = requestAnimationFrame(function () {
|
reqFrame = requestAnimationFrame(function() {
|
||||||
//实际高度
|
//实际高度
|
||||||
const h = unref(realBoxHeight) / 2;
|
const h = unref(realBoxHeight) / 2;
|
||||||
//宽度
|
//宽度
|
||||||
@ -538,8 +539,8 @@ export default defineComponent({
|
|||||||
scrollMove,
|
scrollMove,
|
||||||
scrollInitMove,
|
scrollInitMove,
|
||||||
scrollStartMove,
|
scrollStartMove,
|
||||||
scrollStopMove,
|
scrollStopMove
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
<ul class="item">
|
<ul class="item">
|
||||||
<li v-for="(item, index) in listData" :key="index">
|
<li v-for="(item, index) in listData" :key="index">
|
||||||
<span class="title" v-text="item.title"></span>
|
<span class="title" v-text="item.title"></span>
|
||||||
<span class="date" v-text="item.date"></span>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</SeamlessScroll>
|
</SeamlessScroll>
|
||||||
@ -29,65 +28,56 @@ import { templateRef } from "@vueuse/core";
|
|||||||
import SeamlessScroll from "/@/components/SeamlessScroll";
|
import SeamlessScroll from "/@/components/SeamlessScroll";
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
SeamlessScroll,
|
SeamlessScroll
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const scroll = templateRef<HTMLElement | null>("scroll", null);
|
const scroll = templateRef<HTMLElement | null>("scroll", null);
|
||||||
|
|
||||||
let listData = ref([
|
let listData = ref([
|
||||||
{
|
{
|
||||||
title: "无缝滚动第一行无缝滚动第一行",
|
title: "无缝滚动第一行无缝滚动第一行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第二行无缝滚动第二行",
|
title: "无缝滚动第二行无缝滚动第二行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第三行无缝滚动第三行",
|
title: "无缝滚动第三行无缝滚动第三行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第四行无缝滚动第四行",
|
title: "无缝滚动第四行无缝滚动第四行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第五行无缝滚动第五行",
|
title: "无缝滚动第五行无缝滚动第五行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第六行无缝滚动第六行",
|
title: "无缝滚动第六行无缝滚动第六行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第七行无缝滚动第七行",
|
title: "无缝滚动第七行无缝滚动第七行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第八行无缝滚动第八行",
|
title: "无缝滚动第八行无缝滚动第八行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "无缝滚动第九行无缝滚动第九行",
|
title: "无缝滚动第九行无缝滚动第九行!!!!!!!!!!"
|
||||||
date: "2021-5-1",
|
}
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let classOption = ref({
|
let classOption = ref({
|
||||||
direction: "top",
|
direction: "top"
|
||||||
});
|
});
|
||||||
|
|
||||||
function changeDirection(val) {
|
function changeDirection(val) {
|
||||||
scroll.value.scrollInitMove();
|
scroll.value.reset();
|
||||||
classOption.value.direction = val;
|
classOption.value.direction = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
listData,
|
listData,
|
||||||
classOption,
|
classOption,
|
||||||
changeDirection,
|
changeDirection
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user