Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. import React, { useEffect, useState, useCallback } from "react";
  2. import zenscroll from 'zenscroll';
  3.  
  4. import "./ScrollCircles.css";
  5.  
  6. const ScrollCircles = () => {
  7. const [selectedCircle, setSelectedCircle] = useState("inspiration");
  8. const [isMobile, setIsMobile] = useState(false);
  9. let isScrolling = null;
  10.  
  11. useEffect(() => {
  12. document.addEventListener("scroll", handleScroll, {passive: true});
  13. window.addEventListener("resize", handleResize);
  14. handleResize();
  15. //Unmount
  16. return () => {
  17. clearTimeout(isScrolling);
  18. isScrolling = null;
  19. document.removeEventListener("scroll", handleScroll, {passive: true});
  20. window.removeEventListener("resize", handleResize);
  21. }
  22. }, []);
  23.  
  24. const handleResize = () => {
  25. const mobileQuery = window.matchMedia("(max-width: 600px)");
  26. if(mobileQuery.matches) {
  27. setIsMobile(true);
  28. } else {
  29. setIsMobile(false);
  30. }
  31. }
  32.  
  33. const getPercentOfPageScrolled = () => {
  34. const circles = document.querySelector("#circle-container");
  35. const containerHeight = circles.offsetHeight || circles.scrollTop;
  36. const containerScroll = circles.getBoundingClientRect().top;
  37.  
  38. if(containerScroll < 0) {
  39. return (Math.abs(containerScroll) / containerHeight) * 480;
  40. }
  41.  
  42. else return 0;
  43.  
  44. }
  45.  
  46. const snapToSection = () => {
  47. const scrolled = getPercentOfPageScrolled();
  48. const containerHeight = document.querySelector(".sections").offsetHeight;
  49.  
  50. if(scrolled > 60 && scrolled < 180) {
  51. zenscroll.to(document.querySelector(".idea-section"));
  52. }
  53.  
  54. else if(scrolled >= 180 && scrolled < 300) {
  55. zenscroll.to(document.querySelector(".places-section"));
  56. }
  57.  
  58. else if(scrolled >= 300 && scrolled <= 360) {
  59. zenscroll.to(document.querySelector(".people-section"));
  60. }
  61. }
  62.  
  63. const selectCircles = (scrolled) => {
  64. if(scrolled > 60 && scrolled < 180) {
  65. setSelectedCircle("inspiration");
  66. }
  67.  
  68. else if(scrolled >= 180 && scrolled < 300) {
  69. setSelectedCircle("ideation");
  70. }
  71.  
  72. else if(scrolled >= 300) {
  73. setSelectedCircle("implementation");
  74. }
  75.  
  76. else {
  77. setSelectedCircle("");
  78. }
  79. }
  80.  
  81. const handleScroll = () => {
  82. window.clearTimeout(isScrolling);
  83.  
  84. const circles = document.querySelector(".circles");
  85. const words = document.querySelectorAll(".circle span");
  86.  
  87. const scrolled = getPercentOfPageScrolled();
  88.  
  89. selectCircles(scrolled);
  90.  
  91. if(scrolled > 0 && scrolled < 360) {
  92. document.querySelector(".page-practice").style.backgroundColor = "#000";
  93. }
  94.  
  95. else {
  96. document.querySelector(".page-practice").style.backgroundColor = "#000";
  97. }
  98.  
  99. if(scrolled >= 120 && scrolled <= 360) {
  100. circles.style.transform = `rotate(${scrolled - 120}deg)`;
  101. words.forEach(el => el.style.transform = `rotate(-${scrolled - 120}deg)`);
  102. }
  103.  
  104. else if(scrolled > 360) {
  105. circles.style.transform = `rotate(${240}deg)`;
  106. words.forEach(el => el.style.transform = `rotate(-${240}deg)`);
  107. }
  108.  
  109. else {
  110. circles.style.transform = `rotate(${0}deg)`;
  111. words.forEach(el => el.style.transform = `rotate(-${0}deg)`);
  112. }
  113.  
  114. isScrolling = setTimeout(snapToSection, 66);
  115.  
  116. }
  117.  
  118. return(
  119. <div id="circle-container">
  120. <div className="circles-side">
  121. <div className="circles">
  122. <div className={selectedCircle === "ideation" ? "circle selected-circle" : "circle"}>
  123. <span>Experience</span>
  124. </div>
  125. <div className={selectedCircle === "implementation" ? "circle selected-circle" : "circle"}>
  126. <span>People</span>
  127. </div>
  128. <div className={selectedCircle === "inspiration" ? "circle selected-circle" : "circle"}>
  129. <span>Design</span>
  130. </div>
  131. </div>
  132. </div>
  133. <div className="sections">
  134. <section className={`circle-sections main-section ${selectedCircle === "" ? "visible" : ""}`}>
  135. <h2 className={selectedCircle === "inspiration" ? "text-grey reg lighter" : "text-grey reg lighter"}>
  136. We see these three features most often in our work: design, experience, and people. We use them to ensure success for our clients.
  137. </h2>
  138. </section>
  139. <section className={`circle-sections idea-section ${selectedCircle === "inspiration" ? "visible" : ""}`}>
  140. <h2 className={selectedCircle === "inspiration" ? "text-grey reg lighter" : "text-grey reg lighter"}>
  141. <h3 className="text-red reg text-bold">1</h3>
  142. <br/>
  143. We bring our passion for design to create brands that surprise, delight, and deliver positive emotions.
  144. </h2>
  145. </section>
  146. <section className={`circle-sections places-section ${selectedCircle === "ideation" ? "visible" : ""}`}>
  147. <h2 className={selectedCircle === "ideation" ? "text-grey reg lighter" : "text-grey reg lighter"}>
  148. <h3 className="text-red reg text-bold">2</h3>
  149. <br/>
  150. We guide an organization’s brand across all touchpoints both physical and digital to ensure a meaningful and memorable experience.
  151. </h2>
  152. </section>
  153. <section className={`circle-sections people-section ${selectedCircle === "implementation" ? "visible" : ""}`}>
  154. <h2 className={selectedCircle === "implementation" ? "text-grey reg lighter" : "text-grey reg lighter"}>
  155. <h3 className="text-red reg text-bold">3</h3>
  156. <br/>
  157. We help organization’s bring their brand to life by designing for peoples’ preferences, desires, and values.
  158. </h2>
  159. </section>
  160. </div>
  161. </div>
  162. )
  163. }
  164.  
  165. export default ScrollCircles;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement