<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mostakim Ahamed</title>
    <description>The latest articles on DEV Community by Mostakim Ahamed (@moostakimahamed).</description>
    <link>https://dev.to/moostakimahamed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1477400%2F84e1b669-b108-41fe-8d32-602609c99038.png</url>
      <title>DEV Community: Mostakim Ahamed</title>
      <link>https://dev.to/moostakimahamed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moostakimahamed"/>
    <language>en</language>
    <item>
      <title>Pinning Images with GSAP: A Smooth Scrolling Animation in Next.js</title>
      <dc:creator>Mostakim Ahamed</dc:creator>
      <pubDate>Mon, 14 Oct 2024 16:56:13 +0000</pubDate>
      <link>https://dev.to/moostakimahamed/pinning-images-with-gsap-a-smooth-scrolling-animation-in-nextjs-1274</link>
      <guid>https://dev.to/moostakimahamed/pinning-images-with-gsap-a-smooth-scrolling-animation-in-nextjs-1274</guid>
      <description>&lt;p&gt;In this article, we’ll explore how to create smooth scrolling animations by pinning images using GSAP (GreenSock Animation Platform) and its ScrollTrigger plugin. This technique enhances user experience by creating dynamic effects as users scroll through your content. We’ll use Next.js and Tailwind CSS for styling, ensuring a modern look for our project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Demo&lt;/li&gt;
&lt;li&gt;Installation&lt;/li&gt;
&lt;li&gt;Implementation&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before jumping to the explanation check out the live demo of our pinning images animation on &lt;strong&gt;&lt;em&gt;&lt;a href="https://codesandbox.io/p/devbox/serene-goldwasser-ngsp67" rel="noopener noreferrer"&gt;CodeSandbox &lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;or &lt;strong&gt;&lt;em&gt;&lt;a href="https://www.loom.com/share/c7c43f08d027466da91860de399d2969?sid=8ebb2fde-193b-4f91-ae47-56dcd4fd275e" rel="noopener noreferrer"&gt;Loom&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To get started, make sure you have a Next.js application set up. (Follow Next.js Installation Documentation: &lt;a href="https://nextjs.org/docs/getting-started/installation" rel="noopener noreferrer"&gt;https://nextjs.org/docs/getting-started/installation&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next,&lt;/strong&gt; Tailwind CSS: (Follow tailwind Installation Documentation/Install with next js)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next,&lt;/strong&gt; install the necessary packages for &lt;strong&gt;&lt;em&gt;GSAP:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;npm install gsap @gsap/react&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s create the ScrollAnimation component that will handle our pinning images animation. Here’s the complete code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useRef } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useGSAP } from "@gsap/react";

gsap.registerPlugin(ScrollTrigger); // Register Gsap Scroll Trigger Plugin

// I used freepik images link for this purpose
const imageUrls = [
  "https://img.freepik.com/free-photo/wide-angle-shot-single-tree-growing-clouded-sky-sunset-surrounded-by-grass_181624-22807.jpg?ga=GA1.1.2030075610.1697991259&amp;amp;semt=ais_hybrid-rr-similar",
  "https://img.freepik.com/free-photo/cascade-boat-clean-china-natural-rural_1417-1356.jpg?ga=GA1.1.2030075610.1697991259&amp;amp;semt=ais_hybrid-rr-similar",
  "https://img.freepik.com/free-photo/group-elephants-big-green-tree-wilderness_181624-16897.jpg?ga=GA1.1.2030075610.1697991259&amp;amp;semt=ais_hybrid-rr-similar",
  "https://img.freepik.com/premium-photo/blazing-sun-vast-savanna_1272857-120118.jpg?ga=GA1.1.2030075610.1697991259&amp;amp;semt=ais_hybrid-rr-similar",
  "https://img.freepik.com/free-photo/beautiful-shot-tree-savanna-plains-with-blue-sky_181624-21992.jpg?ga=GA1.1.2030075610.1697991259&amp;amp;semt=ais_hybrid-rr-similar",
];

const ScrollAnimation = () =&amp;gt; {
  const imagesRef = useRef&amp;lt;any[]&amp;gt;([]); // Fix to store multiple refs

  useGSAP(() =&amp;gt; {
    // Convert the current array of image references to a proper array for GSAP manipulation
    const images = gsap.utils.toArray(imagesRef.current);

    // Iterate over each image element
    images.forEach((panel: any, i: number) =&amp;gt; {
      let scale = 1;

      // If the current image is not the last one, adjust the scale based on its index
      if (i !== images.length - 1) {
        scale = 0.9 + 0.025 * i; // Create a slight scaling effect for images based on their index
      }

      gsap.to(panel, {
        scale: scale,
        transformOrigin: "top center", // Specify the point from which the scaling transformation occurs
        ease: "none",

        // Configure the ScrollTrigger plugin for scroll-based animations
        scrollTrigger: {
          trigger: panel, // Set the current image as the trigger for the ScrollTrigger

          // Define when the animation should start based on the position of the trigger
          start: "top " + (70 + 40 * i), // Start the animation when the top of the panel is 70px down plus an offset based on index
          end: "bottom +=650px", // Define when the animation should end (bottom of the panel + 650px)
          endTrigger: ".end", // Specify the end trigger element
          pin: true, // Pin the current panel/image in place while it is being triggered
          pinSpacing: false, // Disable additional spacing around pinned elements
          scrub: true, // Enable scrub for smooth animation with scrolling
        },
      });
    });
  }, []);

  return (
    &amp;lt;div className="flex flex-col gap-12 mx-auto max-w-2xl py-12"&amp;gt;
      {imageUrls.map((image, index) =&amp;gt; (
        &amp;lt;div
          key={index}
          ref={(el) =&amp;gt; (imagesRef.current[index] = el)}
          className=""
        &amp;gt;
          &amp;lt;img
            src={image}
            alt={`Image ${index + 1}`}
            className="w-full h-auto object-cover rounded-lg shadow-lg"
          /&amp;gt;
        &amp;lt;/div&amp;gt;
      ))}
      &amp;lt;div className="end"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default ScrollAnimation;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Understanding the Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Image References:&lt;/strong&gt; We create an array of references using useRef to manipulate our image elements directly.&lt;br&gt;
&lt;strong&gt;GSAP Animations:&lt;/strong&gt; Inside the useEffect, we loop through each image and set a scale based on its index. This creates a dynamic scaling effect as the user scrolls.&lt;br&gt;
&lt;strong&gt;ScrollTrigger Configuration:&lt;/strong&gt; We configure ScrollTrigger for each image, specifying when the animation starts and ends, pinning the images in place while scrolling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To include the ScrollAnimation component in your Next.js application, import it into your main application file (e.g., &lt;strong&gt;&lt;em&gt;page.tsx&lt;/em&gt;&lt;/strong&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ScrollAnimation from "./ScrollAnimation";

export default function Home() {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;div className="h-screen w-full flex items-center justify-center bg-[#66545e]"&amp;gt;
        &amp;lt;h1 className="text-2xl font-bold"&amp;gt;Scroll Down To See The Magic&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
      {/* The ScrollAnimation Component */}
      &amp;lt;ScrollAnimation /&amp;gt;
      &amp;lt;div className="bg-[#aa6f73] h-screen w-full flex items-center justify-center"&amp;gt;
        &amp;lt;h1 className="text-2xl font-bold"&amp;gt;Pinning Image Animation End&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run the application and boom. 💥 💥&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the sandbox link again:&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;&lt;a href="https://codesandbox.io/p/devbox/serene-goldwasser-ngsp67" rel="noopener noreferrer"&gt;CodeSandbox&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You now know how to pin images and create smooth scrolling animations using GSAP and ScrollTrigger in a Next.js application! This technique can greatly enhance the visual appeal of your site. Feel free to customize the images and scaling effects to match your project’s style.&lt;/p&gt;

&lt;p&gt;If you found this article helpful, please share it on social media and leave a comment below. Happy coding! 💻😃&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>gsap</category>
      <category>frontend</category>
      <category>animation</category>
    </item>
    <item>
      <title>Creating a Responsive Navbar Using Material UI in a Next.js Project</title>
      <dc:creator>Mostakim Ahamed</dc:creator>
      <pubDate>Mon, 13 May 2024 12:22:31 +0000</pubDate>
      <link>https://dev.to/moostakimahamed/creating-a-responsive-navbar-using-material-ui-in-a-nextjs-project-2pb0</link>
      <guid>https://dev.to/moostakimahamed/creating-a-responsive-navbar-using-material-ui-in-a-nextjs-project-2pb0</guid>
      <description>&lt;p&gt;This is a step-by-step guide on creating a responsive navbar using &lt;strong&gt;Material UI&lt;/strong&gt; in your Next.js project. Whether you're building a personal portfolio, a business website, or an e-commerce platform, a responsive navbar is essential for providing an intuitive navigation experience across various devices.&lt;/p&gt;

&lt;p&gt;Let's dive into the process:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Setting Up Your Next.js Project&lt;/strong&gt;&lt;br&gt;
To kick things off, let's create a new Next.js application. Open your terminal and run the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npx create-next-app@latest


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then set all necessary steps for creating a basic next js app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Installing Material UI&lt;/strong&gt;&lt;br&gt;
Next, we'll install Material UI. Run the following command in your project directory:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install @mui/material @emotion/react @emotion/styled @mui/icons-material


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. Cleaning Up Your Page Component&lt;/strong&gt;&lt;br&gt;
Once your project is set up, navigate to the default page component and clean it up.&lt;br&gt;
We'll be integrating our navbar component into this page later on&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Creating the Navbar Component&lt;/strong&gt;&lt;br&gt;
Now, let's create our navbar component. Inside the &lt;code&gt;src&lt;/code&gt; folder create a folder named components. Then in your components folder, create a new file named &lt;code&gt;navbar.tsx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I've provided the complete code for the navbar component on GitHub. You can find it &lt;a href="https://github.com/Mostakimw/material-ui-responsive-navbar" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Feel free to explore the code and customize it according to your project's needs. I have already added the necessary comments so that you can understand them easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Integrating the Navbar Component&lt;/strong&gt;&lt;br&gt;
With our navbar component created, it's time to integrate it into our main layout. &lt;br&gt;
In our &lt;code&gt;page&lt;/code&gt; file in the &lt;code&gt;app&lt;/code&gt; directory integrate the navbar component here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufzqjva4kal9zcs1dlsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufzqjva4kal9zcs1dlsb.png" alt="navbar integrate in page file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Starting Your Project&lt;/strong&gt;&lt;br&gt;
To see our navbar in action, run the following command in your terminal to start the Next.js development server:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm run dev


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Visit &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; in your web browser to view your Next.js project with the newly implemented navbar.&lt;br&gt;
Yo! You have done this.&lt;/p&gt;

&lt;p&gt;If you want more explanation you can continue with me!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Exploring the Code&lt;/strong&gt;&lt;br&gt;
Now, let's dive deeper into the code and explore some key aspects of our navbar component:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Menu Items: Customize the menu items according to your project requirements. The &lt;code&gt;menuItems&lt;/code&gt; variable contains the links and labels for each menu item.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hamburger Menu: Our navbar includes a hamburger menu icon for smaller devices. This ensures a seamless navigation experience on mobile and tablet devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responsive Design: The navbar is designed to be responsive, adapting to different screen sizes and orientations. You can adjust the padding, colors, and other styles to suit your project's design.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;This is the final look of large and small devices&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Large device&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxy1lzkm82aslij1gr5n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxxy1lzkm82aslij1gr5n.png" alt="large device navbar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Small device&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxs9ra2g3cu18iqdi7oj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxs9ra2g3cu18iqdi7oj.png" alt="small device navbar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Mostakimw/material-ui-responsive-navbar" rel="noopener noreferrer"&gt;Full-Code-Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to ask anything.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>nextjs</category>
      <category>materialui</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
