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 7419

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

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T03:38:08+00:00 2024-11-28T03:38:08+00:00

Creating a Dynamic Typing Animation in React using Hooks and Bootstrap

  • 60k

Image description
In the world of web development, creating engaging and interactive user interfaces is crucial. One way to captivate your visitors’ attention is by adding dynamic elements to your website. In this article, we’ll walk you through how to create a captivating dynamic typing animation using React hooks and the Bootstrap framework. We’ll break down the code step by step and guide you on where to copy and paste each section.

1. Setting Up the React App

Before we dive into the code, make sure you have a React project set up. If you haven’t already, you can create a new React app using the following command:

npx create-react-app dynamic-typing-animation
install some packages:

npm install react-bootstrap bootstrap react-bootstrap-icons react-on-screen
In your app.js file, you'll import necessary dependencies and the Banner component. This component will serve as the main content of your application. Copy and paste the following code into your app.js file:

 // app.js import logo from "./logo.svg"; import "./App.css"; import "bootstrap/dist/css/bootstrap.min.css"; import { Banner } from "./components/Banner";  function App() {   return (     <div className="App">       <Banner />     </div>   ); }  export default App; 
Enter fullscreen mode Exit fullscreen mode

Next, you’ll implement the dynamic typing animation in the Banner component. This component uses hooks to manage state and timing for the animation.

 // banner.js import { useState, useEffect } from "react"; import { Container, Row, Col } from "react-bootstrap"; import { ArrowRightCircle } from "react-bootstrap-icons"; import TrackVisibility from "react-on-screen";  export const Banner = () => {   const [loopNum, setLoopNum] = useState(0);   const [isDeleting, setIsDeleting] = useState(false);   const [text, setText] = useState("");   const [delta, setDelta] = useState(300 - Math.random() * 100);   const [index, setIndex] = useState(1);   const toRotate = ["Web Developer", "Web Designer", "UI/UX Designer"];   const period = 2000;    useEffect(() => {     let ticker = setInterval(() => {       tick();     }, delta);      return () => {       clearInterval(ticker);     };   }, [text]);    const tick = () => {     let i = loopNum % toRotate.length;     let fullText = toRotate[i];     let updatedText = isDeleting       ? fullText.substring(0, text.length - 1)       : fullText.substring(0, text.length + 1);      setText(updatedText);      if (isDeleting) {       setDelta((prevDelta) => prevDelta / 2);     }      if (!isDeleting && updatedText === fullText) {       setIsDeleting(true);       setIndex((prevIndex) => prevIndex - 1);       setDelta(period);     } else if (isDeleting && updatedText === "") {       setIsDeleting(false);       setLoopNum(loopNum + 1);       setIndex(1);       setDelta(500);     } else {       setIndex((prevIndex) => prevIndex + 1);     }   };    return (     <section className="banner" id="home">       <Container>         <Row className="aligh-items-center">           <Col xs={12} md={6} xl={7}>             <TrackVisibility>               {({ isVisible }) => (                 <div                   className={                     isVisible ? "animate__animated animate__fadeIn" : ""                   }                 >                   <span className="tagline">Welcome to my Portfolio</span>                   <h1>                     {`Hi! I'm Lorem`}{" "}                     <span                       className="txt-rotate"                       dataPeriod="1000"                       data-rotate='[ "Web dev", "Web master", "UI/UX programmer" ]'                     >                       <span className="wrap">{text}</span>                     </span>                   </h1>                   <p>                     Lorem Ipsum is simply dummy text of the printing and                     typesetting industry. Lorem Ipsum has been the industry's                     standard dummy text ever since the 1500s, when an unknown                     printer took a galley of type and scrambled it to make a                     type specimen book.                   </p>                   <button>                     Let’s Connect <ArrowRightCircle size={25} />                   </button>                 </div>               )}             </TrackVisibility>           </Col>           <Col xs={12} md={6} xl={5}>             <TrackVisibility>               {({ isVisible }) => (                 <div                   className={                     isVisible ? "animate__animated animate__zoomIn" : ""                   }                 >                   <img                     src={"https://i.imgur.com/DC4LkuS.png"}                     alt="Header Img"                     style={{ width: 500 }}                   />                 </div>               )}             </TrackVisibility>           </Col>         </Row>       </Container>     </section>   ); }; 
Enter fullscreen mode Exit fullscreen mode

4. Copy and Paste App.css

Finally, add the necessary CSS to style your dynamic typing animation. Copy and paste the following CSS code into your App.css file:

 /* App.css */ /************ Default Css ************/ * {   margin: 0;   padding: 0;   box-sizing: border-box; }  html {   scroll-behavior: smooth;   scroll-padding-top: 75px; }  body {   font-weight: 400;   overflow-x: hidden;   position: relative;   background-color: #121212 !important;   color: #fff !important;   font-family: "Centra", sans-serif !important; }  button {   border: 0;   background-color: transparent; } 
Enter fullscreen mode Exit fullscreen mode

5. Styling Your Dynamic Typing Animation

/************ Banner Css ************/ .banner {   margin-top: 0;   padding: 260px 0 100px 0;   background-image: url("https://i.imgur.com/J0zBNyV.png");   background-position: top center;   background-size: cover;   background-repeat: no-repeat; } .banner .tagline {   font-weight: 700;   letter-spacing: 0.8px;   padding: 8px 10px;   background: linear-gradient(     90.21deg,     rgba(170, 54, 124, 0.5) -5.91%,     rgba(74, 47, 189, 0.5) 111.58%   );   border: 1px solid rgba(255, 255, 255, 0.5);   font-size: 20px;   margin-bottom: 16px;   display: inline-block; } .banner h1 {   font-size: 65px;   font-weight: 700;   letter-spacing: 0.8px;   line-height: 1;   margin-bottom: 20px;   display: block; } .banner p {   color: #b8b8b8;   font-size: 18px;   letter-spacing: 0.8px;   line-height: 1.5em;   width: 96%; } .banner button {   color: #fff;   font-weight: 700;   font-size: 20px;   margin-top: 60px;   letter-spacing: 0.8px;   display: flex;   align-items: center; } .banner button svg {   font-size: 25px;   margin-left: 10px;   transition: 0.3s ease-in-out;   line-height: 1; } .banner button:hover svg {   margin-left: 25px; } .banner img {   animation: updown 3s linear infinite; } @keyframes updown {   0% {     transform: translateY(-20px);   }   50% {     transform: translateY(20px);   }   100% {     transform: translateY(-20px);   } } .txt-rotate > .wrap {   border-right: 0.08em solid #666; } 
Enter fullscreen mode Exit fullscreen mode

6. Run Your React App

With all the code in place, you’re ready to see your dynamic typing animation in action. Open your terminal, navigate to your project directory, and run:

npm start
This will start your development server, and you can view the dynamic typing animation by opening your browser and visiting http://localhost:3000.

Congratulations!

You’ve successfully created a captivating dynamic typing animation using React hooks and the Bootstrap framework. This type of animation can make your website more engaging and visually appealing, providing a unique user experience. Feel free to customize the animation and styling to match your project’s design and branding.

bootstrapnextjsreactwebdev
  • 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 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 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.