Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix projection of fixed elements when scrolling #2647

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions dev/projection/fixed-child-from-static.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<html>
<head>
<style>
body {
padding: 0;
margin: 0;
}

#container {
width: 100px;
height: 100px;
}

#fixed {
position: static;
top: 0;
left: 0;
width: 500px;
height: 100px;
background: #00cc88;
display: flex;
align-items: flex-start;
}

#child {
width: 100px;
height: 100px;
background: #0077ff;
}

#trigger-overflow {
width: 1px;
height: 1px;
position: absolute;
top: 2000px;
left: 2000px;
}

[data-layout-correct="false"] {
background: #dd1144 !important;
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container">
<div id="fixed">
<div id="child"></div>
</div>
</div>
<div id="trigger-overflow"></div>

<script src="../../packages/framer-motion/dist/projection.dev.js"></script>
<script src="./script-assert.js"></script>
<script src="./script-undo.js"></script>
<script>
const { createNode } = window.Undo
const {
matchViewportBox,
matchVisibility,
matchOpacity,
addPageScroll,
} = window.Assert

const fixed = document.getElementById("fixed")
const fixedProjection = createNode(fixed, undefined, {
layoutScroll: true,
layout: true,
})
const fixedOrigin = fixed.getBoundingClientRect()

const child = document.getElementById("child")
const childProjection = createNode(child, fixedProjection)
const childOrigin = child.getBoundingClientRect()

childProjection.willUpdate()
fixedProjection.willUpdate()

const scrollDistance = 100
window.scrollTo(scrollDistance, scrollDistance)
fixed.style.position = "fixed"
fixed.style.justifyContent = "flex-end"

fixedProjection.root.didUpdate()

setTimeout(() => {
matchViewportBox(fixed, {
top: -100,
left: -100,
right: 400,
bottom: 0,
})
matchViewportBox(child, {
top: -100,
left: -100,
right: 0,
bottom: 0,
})
}, 50)
</script>
</body>
</html>
98 changes: 98 additions & 0 deletions dev/projection/fixed-child-page-scroll-layout-change.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<html>
<head>
<style>
body {
padding: 0;
margin: 0;
}

#container {
width: 100px;
height: 100px;
}

#fixed {
position: fixed;
top: 0;
left: 0;
width: 500px;
height: 100px;
background: #00cc88;
display: flex;
align-items: flex-start;
}

#child {
width: 100px;
height: 100px;
background: #0077ff;
}

#trigger-overflow {
width: 1px;
height: 1px;
position: absolute;
top: 2000px;
left: 2000px;
}

[data-layout-correct="false"] {
background: #dd1144 !important;
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container">
<div id="fixed">
<div id="child"></div>
</div>
</div>
<div id="trigger-overflow"></div>

<script src="../../packages/framer-motion/dist/projection.dev.js"></script>
<script src="./script-assert.js"></script>
<script src="./script-undo.js"></script>
<script>
const { createNode } = window.Undo
const {
matchViewportBox,
matchVisibility,
matchOpacity,
addPageScroll,
} = window.Assert

const fixed = document.getElementById("fixed")
const fixedProjection = createNode(fixed, undefined, {
layoutScroll: true,
layout: true,
})
const fixedOrigin = fixed.getBoundingClientRect()

const child = document.getElementById("child")
const childProjection = createNode(child, fixedProjection)
const childOrigin = child.getBoundingClientRect()

childProjection.willUpdate()
fixedProjection.willUpdate()

const scrollDistance = 100
window.scrollTo(scrollDistance, scrollDistance)
fixed.style.justifyContent = "flex-end"
fixed.style.top = "50px"
fixed.style.left = "50px"

fixedProjection.root.didUpdate()

setTimeout(() => {
matchViewportBox(fixed, fixedOrigin)
matchViewportBox(child, {
top: 0,
left: 0,
right: 100,
bottom: 100,
})
}, 50)
</script>
</body>
</html>
96 changes: 96 additions & 0 deletions dev/projection/fixed-child-page-scroll.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<html>
<head>
<style>
body {
padding: 0;
margin: 0;
}

#container {
width: 100px;
height: 100px;
}

#fixed {
position: fixed;
top: 0;
left: 0;
width: 500px;
height: 100px;
background: #00cc88;
display: flex;
align-items: flex-start;
}

#child {
width: 100px;
height: 100px;
background: #0077ff;
}

#trigger-overflow {
width: 1px;
height: 1px;
position: absolute;
top: 2000px;
left: 2000px;
}

[data-layout-correct="false"] {
background: #dd1144 !important;
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container">
<div id="fixed">
<div id="child"></div>
</div>
</div>
<div id="trigger-overflow"></div>

<script src="../../packages/framer-motion/dist/projection.dev.js"></script>
<script src="./script-assert.js"></script>
<script src="./script-undo.js"></script>
<script>
const { createNode } = window.Undo
const {
matchViewportBox,
matchVisibility,
matchOpacity,
addPageScroll,
} = window.Assert

const fixed = document.getElementById("fixed")
const fixedProjection = createNode(fixed, undefined, {
layoutScroll: true,
layout: true,
})
const fixedOrigin = fixed.getBoundingClientRect()

const child = document.getElementById("child")
const childProjection = createNode(child, fixedProjection)
const childOrigin = child.getBoundingClientRect()

childProjection.willUpdate()
fixedProjection.willUpdate()

const scrollDistance = 100
window.scrollTo(scrollDistance, scrollDistance)
fixed.style.justifyContent = "flex-end"

fixedProjection.root.didUpdate()

setTimeout(() => {
matchViewportBox(fixed, fixedOrigin)
matchViewportBox(child, {
top: 0,
left: 0,
right: 100,
bottom: 100,
})
}, 50)
</script>
</body>
</html>
97 changes: 97 additions & 0 deletions dev/projection/fixed-child-to-static.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<html>
<head>
<style>
body {
padding: 0;
margin: 0;
}

#container {
width: 100px;
height: 100px;
}

#fixed {
position: fixed;
top: 0;
left: 0;
width: 500px;
height: 100px;
background: #00cc88;
display: flex;
align-items: flex-start;
}

#child {
width: 100px;
height: 100px;
background: #0077ff;
}

#trigger-overflow {
width: 1px;
height: 1px;
position: absolute;
top: 2000px;
left: 2000px;
}

[data-layout-correct="false"] {
background: #dd1144 !important;
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container">
<div id="fixed">
<div id="child"></div>
</div>
</div>
<div id="trigger-overflow"></div>

<script src="../../packages/framer-motion/dist/projection.dev.js"></script>
<script src="./script-assert.js"></script>
<script src="./script-undo.js"></script>
<script>
const { createNode } = window.Undo
const {
matchViewportBox,
matchVisibility,
matchOpacity,
addPageScroll,
} = window.Assert

const fixed = document.getElementById("fixed")
const fixedProjection = createNode(fixed, undefined, {
layoutScroll: true,
layout: true,
})
const fixedOrigin = fixed.getBoundingClientRect()

const child = document.getElementById("child")
const childProjection = createNode(child, fixedProjection)
const childOrigin = child.getBoundingClientRect()

childProjection.willUpdate()
fixedProjection.willUpdate()

const scrollDistance = 100
window.scrollTo(scrollDistance, scrollDistance)
fixed.style.position = "static"
fixed.style.justifyContent = "flex-end"

fixedProjection.root.didUpdate()

setTimeout(() => {
matchViewportBox(fixed, fixedOrigin)
matchViewportBox(child, {
top: 0,
left: 0,
right: 100,
bottom: 100,
})
}, 50)
</script>
</body>
</html>
Loading