"Create a dynamic entrance and exit effect with Tailwind CSS sliding in and out from

My goal is to create a smooth sliding animation for this div that displays details of a clicked project, transitioning in and out from the right side.

This is my attempt using Tailwind CSS:

{selectedProject !== null && (
        <div
          className={`fixed top-0 right-0 w-full h-full md:w-1/2 z-20 bg-white px-5 py-10 overflow-scroll transform transition duration-600 ${
            selectedProject !== null ? 'translate-x-0' : 'translate-x-full'
          }`}
        >
           <div
              className="flex items-center justify-between w-full px-1 py-2"
              onClick={closeDetails}
          >
             <div>
                <Image
                  src={back}
                  alt={back}
                  quality={100}
                  height={30}
                  width={30}
                  placeholder="blur"
                  className="cursor-pointer"
                />
              </div>
              <Link href="#projects">
                 <div onClick={closeDetails} className="font-bold cursor-pointer">
                    Back to projects
                 </div>
              </Link>
          </div>
          <hr className="pb-10" />
          <p className="text-lg font-extrabold text-black pb-1">{projects[selectedProject].name}</p>
          <p className="text-gray-700 text-base pb-4 ">{projects[selectedProject].details}</p>
          <Image
            src={projects[selectedProject].image}
            alt={`${projects[selectedProject].name} screenshot`}
            quality={100}
            placeholder="blur"
            blurDataURL="iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOMzoyuBwAD5gGgL5NkuQAAAABJRU5ErkJggg=="
            className="h-72 md:h-80 max-w-auto rounded-lg"
          />
          <p className="text-base font-bold text-black pb-1 pt-7">About</p>
          <p className="text-xs md:text-base">{projects[selectedProject].details}</p>
          <p className="text-base font-bold text-black pb-1 pt-7">
            Technologies
          </p>
          <div className="mt-5">
            <div className="flex flex-wrap gap-3 mt-3">
              {projects[selectedProject].skills.map((skill, skillIndex) => (
                <span
                  key={skillIndex}
                  className="w-fit inline-flex items-center rounded-md bg-indigo-50 px-2 py-1 text-sm font-medium text-black ring-1 ring-inset ring-indigo-700/10"
                >
                  {skill}
                </span>
              ))}
            </div>
          </div>
          <div className="w-fit gap-1 flex items-center">
            <Image
              src={earth}
              alt="earth icon"
              quality={100}
              height={20}
              width={20}
              placeholder="blur"
              className="cursor-pointer"
            />
            <p className="text-base font-bold text-black pb-1 pt-7">Website</p>
          </div>
          <Link href={projects[selectedProject].link}>
            {projects[selectedProject].link}
          </Link>
          <div className="w-fit gap-3 flex items-center">
            <Image
              src={github}
              alt="github icon"
              quality={100}
              height={20}
              width={20}
              placeholder="blur"
              className="cursor-pointer"
            />
            <p className="text-base font-bold text-black pb-1 pt-7">Github</p>
          </div>
          <Link href={projects[selectedProject].github}>
            {projects[selectedProject].github}
          </Link>
        </div>
      )}

I am struggling to achieve the desired functionality with this code. The same issue persists when applying a similar feature to my menu bar as well, so finding a solution here should solve multiple problems.

Answer №1

To achieve the desired outcome, consider removing the conditional statement that surrounds the component and focusing solely on styling.

Another option is to utilize a tool like Headless UI transitions for this purpose. If your content relies heavily on the conditional statement,

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

send back information obtained via an ajax request made by a javascript module

Here is a code snippet featuring an object with a function that makes an AJAX call. The function currently returns an empty array, but we need to figure out how to return the data after receiving the response. var receivedData = []; var AjaxUtil = { ...

Troubleshooting Problems with Ruby Arrays, JavaScript, and JSON

I am facing a challenge with rendering a highcharts plugin in my rails application. I suspect it could be related to the sql queries fetching data from the database and converting them into a ruby array that the javascript code fails to interpret correctly ...

Display a loading spinner on the browser while the form is being submitted

My current project involves using AJAX to retrieve data and populate a form. The data being fetched is quite large, resulting in a delay as it is fetched from the database and filled into the form fields. During this process, I display a loading icon to in ...

The jQuery functions seem to be malfunctioning when trying to retrieve elements by their ids

I'm having trouble with the click function when using IDs, but it works fine with classes. $('#myTab li a').click(function(e) {} When I switch to using classes like this: $('.nav-tabs a.overview').click(function(e) {} it work ...

Boost the scrolling velocity of my sidebar using Jquery

Hello there, I am completely new to the world of web development and particularly to using JavaScript and jQuery. I am interested in learning how to adjust the speed at which my Sidebar scrolls down as the user navigates through the page. Here is the jQue ...

Enhance the textarea using Javascript when clicked

I am experimenting with styling my textarea using a combination of JAVASCRIPT and CSS. The goal is to make it expand in size from 20px height to 120px height when clicked, using document.getElementById("tweet_area"). However, I am facing an issue where t ...

Utilizing Windows Azure and restify for node.js Development

I have an azure website with a URL like: . In my server.js file, I have the following code: var restify = require('restify'); function respond(req, res, next) { res.send('hello ' + req.params.name); next(); } var server = restify ...

Dynamically inserting templates into directives

I've been attempting to dynamically add a template within my Angular directive. Following the guidance in this answer, I utilized the link function to compile the variable into an HTML element. However, despite my efforts, I haven't been success ...

Refreshing the page causes JavaScript to fail loading

Recently, I encountered a puzzling error. Upon visiting this link The carousel fails to load properly near the bottom of the page. However, if you click on the logo or navigate back to the home page, it works fine. Additionally, performing a command + r ...

VSCode is experiencing issues with recognizing .env* files for markup purposes and is also failing to recognize .env.local.* files

Current Environment: Utilizing NextJs, React, and VsCode Noticing a problem with syntax highlighting in my VSCODE editor. I have installed the following extensions: ENV DotEnv As per suggestions, I updated my json configuration file as follows: " ...

Image missing aria-label attribute

I am facing an issue with getting the aria-label to display on my image. Despite checking my code, I cannot figure out why it is not working. Any ideas on what might be missing? Here is the code from my NextJS app: The svg in my public folder. <?xml v ...

Is there a way to deactivate a clickable div immediately after it has been clicked on?

I have been searching for a solution to this particular question on different platforms, including Stack Overflow. However, I am looking for an answer using pure JavaScript only, so please avoid jQuery solutions. In order to provide context, I have includ ...

What could be causing Node Pdfkit to sometimes generate a corrupted file within my code?

I've encountered an issue with my function that generates a PDF file and sends it via email using `pdfkit` and `nodemailer`. Occasionally, I receive a file that cannot be opened. I'm unsure why this happens sporadically while it works fine most o ...

Using the fieldset element in AngularJS Material causes disruptions in my flex layout

My current issue can be illustrated through two code examples: The first example functions properly when the fieldset is not included. In the second example, including the fieldset causes the layout to extend beyond the window when there is long text (in ...

Guide to successfully downloading an xlsx file in angular through express

I am creating an xlsx file based on user input within the express framework. The data is sent via a post request and I intend to send back the file content using res.download(...). However, when I do this, the data field in my ajax response ends up contai ...

Kendo Template Function: Angular JS version 1.6

I'm working with a currency column that looks like this: { field: 'INVOICE_AMOUNT_ORIGINAL', title: $translate.instant('invoiceAmount'), format: '{0:n}', template: '#= currency(dataItem.INVOICE_AMOUNT_ORIGIN ...

Removing a value from an array contained within an object

I have a scenario in my task management application where I want to remove completed tasks from the MongoDB database when a logged-in user marks them as done. Below is the snippet of code for my Schema. const user = new mongoose.Schema({ username : Str ...

The ActionController is encountering an UnknownFormat error when trying to respond to AJAX requests with js using

I've been scouring the internet for information on this topic, but I'm having trouble understanding how AJAX works with Rails. I've gone through the documentation multiple times and it's just not clicking for me. From what I gather, AJ ...

What causes my Excel file to become corrupted when inputting new data?

My intention with this code is to insert "ABC" into cell B3 of an existing Excel document. However, when the file is written, its size decreases significantly and Excel is unable to open it. const excel = require("exceljs"); const template = "./myexcel.xl ...

Error: Uncaught TypeError - Unable to access the 'handleClick' property of undefined within a forEach loop

I came across the following code snippet articles_list.jsx import React from 'react'; import './articles_list.css'; export default class ArticlesList extends React.Component { constructor(props) { super(props); this.state ...