visible.rs 3.5 KB

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