Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3967

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T07:37:08+00:00 2024-11-26T07:37:08+00:00

Some amazing JS components

  • 61k

We all want to make this cool website with all these amazing features, well I'll help with some of those features like;

  1. React-scroll: This react component that helps to animate vertical scrolling on your webpage/web app. Cool right🤗 ?

  2. React intersection observer: This is another amazing js component that you can implement in your web project to do anything like animation, text/ background color change, etc. The react intersection observer tells you when an element enters a certain viewport.

Why all this explanation with no example 🙄, Don't worry I got you covered ;).

This is an example of using the above react components in your web project.

Result

The link to check out the above demonstration is here or check out my git repo here

Let get buildy 👷🏻‍♂️🛠️

Technologies Used

  • Next Js
  • Tailwind CSS
  • React-scroll
  • React-intersection-observer

After a successful Installation of the above technologies, the folders in code editor should be similar to:

Code editor

Step 1

Go to your Index.js file inside the pages folder and
import theses necessary components to be used in the example

import { Link, Element } from "react-scroll"; import { useInView } from "react-intersection-observer"; 
Enter fullscreen mode Exit fullscreen mode

The Link class imported from the react-scroll component serves as a link to the Element class also imported.
Which means the Link_scrolls to the specified _Element.

Whereby the useInView hook checks if a particular element is in view when scrolling action a]happens on the screen.

Step 2

Copy this into the Home default function

// These are references to each page shown   const { ref: PAGE_ONE, inView: viewOne } = useInView({     threshold: 0.3,   });   const { ref: PAGE_TWO, inView: viewTwo } = useInView({     threshold: 0.3,   });   const { ref: PAGE_THREE, inView: viewThree } = useInView({     threshold: 0.3,   });   const { ref: PAGE_FOUR, inView: viewFour } = useInView({     threshold: 0.3,   });  // An array of each page and its details   const pagesAndDetails = [     { title: "PAGE_ONE", details: "Details of Page One" },     { title: "PAGE_TWO", details: "Details of Page Two" },     { title: "PAGE_THREE", details: "Details of Page Three" },     { title: "PAGE_FOUR", details: "Details of Page Four" },   ]; // An array of each page's colors   const colors = ["#b8c7ce ", "#E9E948", "#f1f1f1 ", "#7bc191"]; 
Enter fullscreen mode Exit fullscreen mode

Step 3

Copt this into the return function

<>       <Head>         <title>React Scroll Web</title>         <meta           name="description"           content="An example of a react scroll website"         />         <link rel="icon" href="/favicon.ico" />       </Head>        <div className="w-full">         <div className="flex flex-wrap items-center justify-between px-12 fixed">           <Link             activeClass="active"             to="PAGE ONE"             spy             smooth             duration={700}             className="px-3 py-3 mb-2 bg-[#b8c7ce] rounded-xl border-2 border-white cursor-pointer mr-4"           >             {viewOne ? (               <span>YOU ARE AT {pagesAndDetails[0].title}</span>             ) : (               <span> GO TO {pagesAndDetails[0].title}</span>             )}           </Link>           <Link             activeClass="active"             to="PAGE TWO"             spy             smooth             duration={700}             className="px-3 py-3 mb-2 bg-[#E9E948] rounded-xl border-2 border-white cursor-pointer  mr-4"           >             {viewTwo ? (               <span>YOU ARE AT {pagesAndDetails[1].title}</span>             ) : (               <span> GO TO {pagesAndDetails[1].title}</span>             )}           </Link>           <Link             activeClass="active"             to="PAGE THREE"             spy             smooth             duration={700}             className="px-3 py-3 mb-2 bg-[#f1f1f1] rounded-xl border-2 border-white cursor-pointer mr-4"           >             {viewThree ? (               <span>YOU ARE AT {pagesAndDetails[2].title}</span>             ) : (               <span> GO TO {pagesAndDetails[2].title}</span>             )}           </Link>           <Link             activeClass="active"             to="PAGE FOUR"             spy             smooth             duration={700}             className="px-3 py-3 mb-2 bg-[#7bc191] rounded-xl border-2 border-white cursor-pointer mr-4"           >             {viewFour ? (               <span>YOU ARE AT {pagesAndDetails[3].title}</span>             ) : (               <span> GO TO {pagesAndDetails[3].title}</span>             )}           </Link>         </div>          <Element           name="PAGE ONE"           className={`w-full h-screen py-3`}           style={{             backgroundColor: colors[0],           }}         >           <div             ref={PAGE_ONE}             className={`w-full h-full -mt-16 flex flex-col items-center text-center justify-center `}           >             <div className={`w-full mt-2 py-5 font-bold text-2xl `}>               {pagesAndDetails[0].title}             </div>             <div className="w-full  text-sm">{pagesAndDetails[0].details}</div>           </div>         </Element>         <Element           name="PAGE TWO"           className={`w-full h-screen py-3`}           style={{             backgroundColor: colors[1],           }}         >           <div             ref={PAGE_TWO}             className={`w-full h-full -mt-16 flex flex-col items-center text-center justify-center `}           >             <div className={`w-full mt-2 py-5 font-bold text-2xl `}>               {pagesAndDetails[1].title}             </div>             <div className="w-full  text-sm">{pagesAndDetails[1].details}</div>           </div>         </Element>         <Element           name="PAGE THREE"           className={`w-full h-screen py-3`}           style={{             backgroundColor: colors[2],           }}         >           <div             ref={PAGE_THREE}             className={`w-full h-full -mt-16 flex flex-col items-center text-center justify-center `}           >             <div className={`w-full mt-2 py-5 font-bold text-2xl `}>               {pagesAndDetails[2].title}             </div>             <div className="w-full  text-sm">{pagesAndDetails[2].details}</div>           </div>         </Element>         <Element           name="PAGE FOUR"           className={`w-full h-screen py-3`}           style={{             backgroundColor: colors[3],           }}         >           <div             ref={PAGE_FOUR}             className={`w-full h-full -mt-16 flex flex-col items-center text-center justify-center `}           >             <div className={`w-full mt-2 py-5 font-bold text-2xl `}>               {pagesAndDetails[3].title}             </div>             <div className="w-full  text-sm">{pagesAndDetails[3].details}</div>           </div>         </Element>       </div>     </> 
Enter fullscreen mode Exit fullscreen mode

The above code links each button to a page element and changes text when the page is in view.

Step 4

Run the project

npm run dev    // or  yarn dev 
Enter fullscreen mode Exit fullscreen mode

Great work 🎊🎊🎉🎉

There are more better ways to use these components in your project this is just a simple example.

Look out for more amazing JS components.

beginnersjavascriptreactwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.