forked from motiondivision/motion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95fe903
commit 61cfc9e
Showing
8 changed files
with
229 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"baseUrl": "http://0.0.0.0:9990", | ||
"baseUrl": "http://localhost:9990", | ||
"video": true, | ||
"screenshots": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
describe("whileInView", () => { | ||
it("Animates when an element enters the viewport", () => { | ||
cy.visit("?test=while-in-view") | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("Out") | ||
}) | ||
|
||
cy.scrollTo(0, 50) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("In") | ||
}) | ||
}) | ||
|
||
it("Animates when an element leaves the viewport", () => { | ||
cy.visit("?test=while-in-view") | ||
.wait(50) | ||
.scrollTo(0, 0) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("Out") | ||
}) | ||
}) | ||
|
||
it("Animates only when all an element enters the viewport and amount='all'", () => { | ||
cy.visit("?test=while-in-view&amount=all") | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
}) | ||
|
||
cy.scrollTo(0, 50) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
}) | ||
|
||
cy.scrollTo(0, 150) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
}) | ||
}) | ||
|
||
it("Animates when an element enters the viewport once", () => { | ||
cy.visit("?test=while-in-view&once=true") | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("Out") | ||
}) | ||
|
||
cy.scrollTo(0, 50) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("In") | ||
}) | ||
|
||
cy.scrollTo(0, 0) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("In") | ||
}) | ||
}) | ||
|
||
it("Animates when entering a custom root", () => { | ||
cy.visit("?test=while-in-view-custom-root") | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
}) | ||
.get("#container") | ||
.scrollTo(500, 0) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
}) | ||
.get("#container") | ||
.scrollTo(0, 0) | ||
.wait(50) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(255, 0, 0)" | ||
) | ||
}) | ||
}) | ||
|
||
/** | ||
* Manually verified this does work but headless browser not respecting margin | ||
*/ | ||
it.skip("Respects margin", () => { | ||
cy.visit("?test=while-in-view&margin=100px") | ||
.wait(100) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("In") | ||
}) | ||
}) | ||
|
||
it("If IntersectionObserver doesn't exist, immediately animates to whileInView", () => { | ||
cy.visit("?test=while-in-view&delete=true") | ||
.wait(100) | ||
.get("#box") | ||
.should(([$element]: any) => { | ||
expect($element.style.backgroundColor).to.equal( | ||
"rgb(0, 255, 0)" | ||
) | ||
expect($element.innerHTML).to.equal("In") | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { motion } from "@framer" | ||
import * as React from "react" | ||
|
||
export const App = () => { | ||
const containerRef = React.useRef(null) | ||
|
||
return ( | ||
<div id="container" style={container} ref={containerRef}> | ||
<div style={{ flex: "0 0 400px" }} /> | ||
<motion.div | ||
id="box" | ||
initial={false} | ||
transition={{ duration: 0.01 }} | ||
animate={{ background: "rgba(255,0,0,1)" }} | ||
whileInView={{ background: "rgba(0,255,0,1)" }} | ||
viewport={{ root: containerRef }} | ||
style={{ width: 100, height: 100, flexShrink: 0 }} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
const container = { | ||
width: 300, | ||
overflow: "scroll", | ||
display: "flex", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { motion } from "@framer" | ||
import * as React from "react" | ||
|
||
export const App = () => { | ||
const params = new URLSearchParams(window.location.search) | ||
const amount = params.get("amount") || undefined | ||
const once = params.get("once") ? true : undefined | ||
const margin = params.get("margin") || undefined | ||
const deleteObserver = params.get("delete") || undefined | ||
const [inViewport, setInViewport] = React.useState(false) | ||
|
||
if (deleteObserver) { | ||
window.IntersectionObserver = undefined | ||
} | ||
|
||
return ( | ||
<div style={container}> | ||
<motion.div | ||
id="box" | ||
initial={false} | ||
transition={{ duration: 0.01 }} | ||
animate={{ background: "rgba(255,0,0,1)" }} | ||
whileInView={{ background: "rgba(0,255,0,1)" }} | ||
viewport={{ amount, once, margin }} | ||
style={{ width: 100, height: 100 }} | ||
onViewportEnter={() => setInViewport(true)} | ||
onViewportLeave={() => setInViewport(false)} | ||
> | ||
{inViewport ? "In" : "Out"} | ||
</motion.div> | ||
</div> | ||
) | ||
} | ||
|
||
const container = { | ||
paddingTop: 700, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters