已给版本,等待重现icon移动时位置偏差的bug

This commit is contained in:
梁泽军 2025-03-04 17:57:47 +08:00
parent 2e5cde7d62
commit bddae0d362

View File

@ -95,7 +95,7 @@ const isDone = ref(false)
const isShowDone = ref(false) const isShowDone = ref(false)
const xflIconRef = ref(null) const xflIconRef = ref(null)
const currentProgress = ref(0) // const currentProgress = ref(0) //
const debounce = ref(false) const debounce = ref(true)
let animation = null let animation = null
// //
@ -219,12 +219,21 @@ const convertCoordinates = (point) => {
const svg = document.querySelector('.path-svg') const svg = document.querySelector('.path-svg')
const pt = svg.createSVGPoint() const pt = svg.createSVGPoint()
pt.x = point.x // 1pxiOS
pt.y = point.y pt.x = point.x + 1
return pt.matrixTransform(svg.getScreenCTM().inverse()) pt.y = point.y + 1
//
const dpr = window.devicePixelRatio || 1
const screenPoint = pt.matrixTransform(svg.getScreenCTM().inverse())
return {
x: Math.round(screenPoint.x * dpr),
y: Math.round(screenPoint.y * dpr)
}
} }
const initSvgAnimation = () => { const initSvgAnimation = async () => {
// SVG // SVG
const svg = document.querySelector('.path-svg') const svg = document.querySelector('.path-svg')
const path = document.querySelector('#motionPath') const path = document.querySelector('#motionPath')
@ -254,10 +263,19 @@ const initSvgAnimation = () => {
force3D: true // GPU force3D: true // GPU
}) })
// 2
await new Promise(resolve => requestAnimationFrame(resolve))
await new Promise(resolve => requestAnimationFrame(resolve))
//
void path.offsetHeight
// //
gsap.set(xflIconRef.value, { gsap.set(xflIconRef.value, {
x: convertCoordinates(path.getPointAtLength(0)).x, x: convertCoordinates(path.getPointAtLength(0)).x,
y: convertCoordinates(path.getPointAtLength(0)).y y: convertCoordinates(path.getPointAtLength(0)).y,
force3D: true
}) })
@ -368,6 +386,7 @@ const animationFn = () => {
repeat: -1, repeat: -1,
yoyo: true, yoyo: true,
ease: "bounce.out()", ease: "bounce.out()",
}) })
} }
}); });
@ -426,8 +445,11 @@ const animationFn = () => {
x: 20, x: 20,
duration: 1, duration: 1,
ease: "back.inOut(3)", ease: "back.inOut(3)",
}) onComplete: () => {
debounce.value = false
}
})
@ -650,22 +672,24 @@ const animationFn = () => {
.line-box { .line-box {
@include pos(348px, 1048px, 185px, 583px); @include pos(348px, 1048px, 185px, 583px);
overflow: visible; // overflow: visible;
pointer-events: none; pointer-events: none;
/* 确保元素可超出容器 */ /* 确保元素可超出容器 */
.path-svg { .path-svg {
width: 100%; width: 100%;
height: 100%; height: 100%;
transform: translateZ(0); // transform: translateZ(0);
opacity: 0; opacity: 0;
/* 修复渲染层级 */ /* 修复渲染层级 */
backface-visibility: hidden;
/* 修复iOS偏移 */
} }
.xfl-icon { .xfl-icon {
pointer-events: none; pointer-events: none;
// position: absolute; position: absolute;
width: 163px; width: 163px;
height: 153px; height: 153px;
// 1.5 // 1.5
@ -686,16 +710,5 @@ const animationFn = () => {
} }
} }
// .box {
// width: 30px;
// height: 30px;
// background-color: #42b983;
// position: absolute;
// left: 0;
// top: 0;
// transform: translate(-50%, -50%);
// will-change: transform;
// /* */
// }
} }
</style> </style>