fix: reset xPos and yPos in seamlessScroll

This commit is contained in:
xiaoxian521 2021-04-15 19:40:38 +08:00
parent e09ed0fb47
commit f886a38694
2 changed files with 33 additions and 42 deletions

View File

@ -30,7 +30,7 @@ import {
ref,
unref,
watchEffect,
nextTick,
nextTick
} from "vue";
import { tryOnMounted, tryOnUnmounted, templateRef } from "@vueuse/core";
import * as utilsMethods from "./utils";
@ -56,14 +56,14 @@ export default defineComponent({
type: Array,
default: () => {
return [];
},
}
},
classOption: {
type: Object,
default: () => {
return {};
},
},
}
}
},
emits: ["ScrollEnd"],
setup(props, { emit }) {
@ -117,7 +117,7 @@ export default defineComponent({
switchDelay: 400,
switchDisabledClass: "disabled",
// singleWidth/singleHeight rem
isSingleRemUnit: false,
isSingleRemUnit: false
};
});
@ -138,17 +138,16 @@ export default defineComponent({
return {
position: "absolute",
margin: `${unref(height) / 2}px 0 0 -${unref(options).switchOffset}px`,
transform: "translate(-100%,-50%)",
transform: "translate(-100%,-50%)"
};
});
let rightSwitch = computed(() => {
return {
position: "absolute",
margin: `${unref(height) / 2}px 0 0 ${
unref(width) + unref(options).switchOffset
}px`,
transform: "translateY(-50%)",
margin: `${unref(height) / 2}px 0 0 ${unref(width) +
unref(options).switchOffset}px`,
transform: "translateY(-50%)"
};
});
@ -169,7 +168,7 @@ export default defineComponent({
return {
transform: `translate(${unref(xPos)}px,${unref(yPos)}px)`,
transition: `all ${ease} ${unref(delay)}ms`,
overflow: "hidden",
overflow: "hidden"
};
});
@ -225,6 +224,8 @@ export default defineComponent({
});
function reset() {
xPos.value = 0;
yPos.value = 0;
scrollCancle();
scrollInitMove();
}
@ -265,7 +266,7 @@ export default defineComponent({
//touch
startPos = {
x: touch.pageX,
y: touch.pageY,
y: touch.pageY
};
//touchStartposY
startPosY = unref(yPos);
@ -293,7 +294,7 @@ export default defineComponent({
const { direction } = unref(options);
let endPos = {
x: touch.pageX - startPos.x,
y: touch.pageY - startPos.y,
y: touch.pageY - startPos.y
};
//
e.preventDefault();
@ -350,7 +351,7 @@ export default defineComponent({
if (isHover) return;
//move touchMove
scrollCancle();
reqFrame = requestAnimationFrame(function () {
reqFrame = requestAnimationFrame(function() {
//
const h = unref(realBoxHeight) / 2;
//
@ -538,8 +539,8 @@ export default defineComponent({
scrollMove,
scrollInitMove,
scrollStartMove,
scrollStopMove,
scrollStopMove
};
},
}
});
</script>

View File

@ -14,7 +14,6 @@
<ul class="item">
<li v-for="(item, index) in listData" :key="index">
<span class="title" v-text="item.title"></span>
<span class="date" v-text="item.date"></span>
</li>
</ul>
</SeamlessScroll>
@ -29,65 +28,56 @@ import { templateRef } from "@vueuse/core";
import SeamlessScroll from "/@/components/SeamlessScroll";
export default {
components: {
SeamlessScroll,
SeamlessScroll
},
setup() {
const scroll = templateRef<HTMLElement | null>("scroll", null);
let listData = ref([
{
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",
},
title: "无缝滚动第九行无缝滚动第九行!!!!!!!!!!"
}
]);
let classOption = ref({
direction: "top",
direction: "top"
});
function changeDirection(val) {
scroll.value.scrollInitMove();
scroll.value.reset();
classOption.value.direction = val;
}
return {
listData,
classOption,
changeDirection,
changeDirection
};
},
}
};
</script>