|
| 1 | +//! Port of the https://codepen.io/ryanfinni/pen/VwZeGxN example |
| 2 | +
|
| 3 | +use dioxus::prelude::*; |
| 4 | + |
| 5 | +fn main() { |
| 6 | + dioxus::launch(app); |
| 7 | +} |
| 8 | + |
| 9 | +fn app() -> Element { |
| 10 | + let mut animated_classes = use_signal(|| ["animated-text", ""]); |
| 11 | + |
| 12 | + rsx! { |
| 13 | + document::Link { rel: "stylesheet", href: asset!("./examples/assets/visible.css") } |
| 14 | + |
| 15 | + div { |
| 16 | + class: "container", |
| 17 | + |
| 18 | + p { |
| 19 | + "Scroll to the bottom of the page. The text will transition in when it becomes visible in the viewport." |
| 20 | + } |
| 21 | + |
| 22 | + p { |
| 23 | + "First, let's create a new project for our hacker news app. We can use the CLI to create a new |
| 24 | + project. You can select a platform of your choice or view the getting started guide for more information |
| 25 | + on each option. If you aren't sure what platform to try out, we recommend getting started with web or |
| 26 | + desktop:" |
| 27 | + } |
| 28 | + |
| 29 | + p { |
| 30 | + "The template contains some boilerplate to help you get started. For this guide, we will be rebuilding some of the code |
| 31 | + from scratch for learning purposes. You can clear the src/main.rs file. We will be adding new code in the next |
| 32 | + sections." |
| 33 | + } |
| 34 | + |
| 35 | + p { |
| 36 | + "Next, let's setup our dependencies. We need to set up a few dependencies to work with the hacker news API: " |
| 37 | + } |
| 38 | + |
| 39 | + p { |
| 40 | + "First, let's create a new project for our hacker news app. We can use the CLI to create a new |
| 41 | + project. You can select a platform of your choice or view the getting started guide for more information |
| 42 | + on each option. If you aren't sure what platform to try out, we recommend getting started with web or |
| 43 | + desktop:" |
| 44 | + } |
| 45 | + |
| 46 | + p { |
| 47 | + "The template contains some boilerplate to help you get started. For this guide, we will be rebuilding some of the code |
| 48 | + from scratch for learning purposes. You can clear the src/main.rs file. We will be adding new code in the next |
| 49 | + sections." |
| 50 | + } |
| 51 | + |
| 52 | + p { |
| 53 | + "Next, let's setup our dependencies. We need to set up a few dependencies to work with the hacker news API: " |
| 54 | + } |
| 55 | + |
| 56 | + p { |
| 57 | + "First, let's create a new project for our hacker news app. We can use the CLI to create a new |
| 58 | + project. You can select a platform of your choice or view the getting started guide for more information |
| 59 | + on each option. If you aren't sure what platform to try out, we recommend getting started with web or |
| 60 | + desktop:" |
| 61 | + } |
| 62 | + |
| 63 | + p { |
| 64 | + "The template contains some boilerplate to help you get started. For this guide, we will be rebuilding some of the code |
| 65 | + from scratch for learning purposes. You can clear the src/main.rs file. We will be adding new code in the next |
| 66 | + sections." |
| 67 | + } |
| 68 | + |
| 69 | + p { |
| 70 | + "Next, let's setup our dependencies. We need to set up a few dependencies to work with the hacker news API: " |
| 71 | + } |
| 72 | + |
| 73 | + h2 { |
| 74 | + class: animated_classes().join(" "), |
| 75 | + onvisible: move |evt| { |
| 76 | + let data = evt.data(); |
| 77 | + if let Ok(is_intersecting) = data.is_intersecting() { |
| 78 | + animated_classes.write()[1] = if is_intersecting { "visible" } else { "" }; |
| 79 | + } |
| 80 | + }, |
| 81 | + |
| 82 | + "Animated Text" |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments