Enhancing webpage aesthetics with CSS transitions and a full-page div overlay

As of now, I have a page with a 'see more' link that reveals a full-page div overlay. The implementation may not be perfect, but it's functional. Here is the link to the page: https://jsfiddle.net/6241cphL/3/

I am looking to enhance the user experience by incorporating CSS transitions to make the overlay appear and disappear more smoothly. Is there a way to achieve this?

Prior to reaching out here, I attempted various approaches:

  • I experimented with adding hidden and visible classes through JavaScript to control the display of elements.
  • I also tried to implement a fade-in/fade-out model and explore menu examples without success.

Note: I acknowledge that my current solution may not be ideal, but for my purposes, it works well. While I welcome constructive feedback, I would appreciate suggestions on improving the existing framework to achieve the desired outcome. :)

Answer №1

Click to switch on the overlay class:

var overlay = document.getElementById("overlay");

function toggleOverlay() {
  overlay.classList.toggle("active");
}
#overlay {
  position: fixed;
  left:0; top:0; bottom:0; right:0;
  background: rgba(0,0,0, 0.3);
  transition: 0.5s;
  
  opacity: 0;
  visibility: hidden;
}
#overlay.active {
  opacity: 1;
  visibility: visible;
}
<button onclick="toggleOverlay()">Display overlay</button>

<div id="overlay">
  <button onclick="toggleOverlay()">Close</button>
</div>

Answer №2

To avoid setting inline styles, consider adding or removing a class name (such as active). This allows you to take advantage of CSS transitions and animations. Utilize the transitionend event or similar methods if you wish to apply another class name once the transition is complete (e.g. inactive), which can be helpful for adjusting properties like visibility: hidden.

Answer №3

There are various methods to accomplish this task. Here is another approach:

var right_link = document.getElementById('right_link');
var inn = document.getElementById('inner');
var link = document.getElementById('link');

function toggleVisibility() {
  if (inn.classList.contains('active')) {
    inn.classList.remove('active');
  } else {
    inn.classList.add('active');
  }
}
right_link.addEventListener('click', toggleVisibility)
#inner {
  border-radius: 100%;
  height: 0;
  left: 50%;
  position: absolute;
  top: 50%;
  width: 0;
  transform: translate(-50%, -50%);
  transition: all .3s;
}

#inner.active {
  background-color: #888888;
  border-radius: 100%;
  height: 300px;
  left: 50%;
  position: absolute;
  top: 50%;
  width: 300px;
  transform: translate(-50%, -50%);
  transition: all .3s;
}
<span id="right_link">Click me</span>
<div id="inner">
</div>

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

Addressing the status bar gap issue on the iPhone X with Cordova for iOS 11.0

After receiving helpful feedback on my previous Cordova question regarding status bars, I've encountered a new issue with the iPhone X on iOS 11.0. I came across this thread: Users are reporting a white bar appearing specifically on the iPhone X run ...

Angular 2 ngSubmit triggers unexpectedly on occasions when it is not supposed to

Currently, I am working on developing an Ionic 3 application with Angular 2 and TypeScript. In the app, there is a form that is responsible for sending data to our server. The issue I am facing is that whenever I click on the following button: <butto ...

What is the best way to save data from a jQuery plugin to a database using ASP .NET MVC?

I have a jQuery plugin called "Slider" that displays the current price of an item. I would like to enhance it by allowing users to change prices using the jQuery slider and update them in the database. Here is the model: public class Item { public in ...

Using Express JS to implement a post method for multipart form data transmission

I recently attempted to send form data to my express js server. Below is the code snippet from my pug file: form(action="/profile" method="post" enctype="multipart/form-data") input(type="file" accept="image/*" name="profileimage") input(type="text" nam ...

The jQuery .on('click') event is only functioning properly the first time it is clicked

Recently, I encountered a peculiar issue with an on-click event that seems to work only once. The intended functionality is to toggle the .p-active class, but instead, it only adds it. The problem arises from dynamically added content post-click using lig ...

Utilizing the GET method within a form

I'm currently working on testing a form to ensure that my input values are being submitted correctly. At this point, I haven't set up any server script yet. However, I was hoping that upon clicking submit, I would be able to see my values appende ...

Encountering a "DOM Exception 11: InvalidStateError" when attempting to use websocket.send

I encountered the following error message: DOM Invalidate exception 11 This error is coming from the code snippet below, but I'm having trouble identifying the root cause. /*The coding style may appear pseudo-stylish with potential syntax errors*/ ...

What is the solution to fixing the JSON parsing error that says 'JSON.parse: bad control character in string literal'?

When sending data from NodeJS Backend to the client, I utilize the following code: res.end(filex.replace("<userdata>", JSON.stringify({name:user.name, uid:user._id, profile:user.profile}) )) //No errors occur here and the object is successfully stri ...

Is it feasible to activate a Bootstrap Tooltip from a different element?

I am currently developing a system that enables users to add notes over an image they upload. Presently, I have a note div that, upon clicking, opens a text box for editing. When hovering over this div, I utilize Bootstrap Tooltip to preview the contents o ...

Guide on adding CSS files to Next.js 14

I'm currently working with nextjs 14 and I need help figuring out how to add 'style.css' and other custom css files to my nextjs project. Here is my current file structure: my-project/ ├── components/ │ ├── footer.tsx │ ...

In what way can a pointlight be directed towards a specific angle?

Is it possible to use a PointLight as a SpotLight when my camera is facing in the negative z direction and the pointlight is directed towards (0, 0, 0)? How can I adjust the pointlight to target (0, 0, -100) instead? ...

Adjust and resize video backgrounds within parent elements on iframes

Consider the code snippet below: <div class="viewport"> <iframe src="youtube.com/blabla"></iframe> </div> Accompanied by this CSS: .viewport { height: 100vh; width: 100%; } iframe { position: absolute; } If we t ...

Using jQuery to target multiple div elements sharing a common class that are separate from the currently selected div

I am facing a challenge with a div that has a variable number of specific children that I need to toggle between hide and show. It's difficult to explain, but the following code provides a clear example. <div class="item_content_container"> ...

"Unleashing the fun: incorporating a variety of random songs into your

My goal is to create a central button on my webpage that, when clicked, will trigger a playlist of randomly selected songs. Once pressed, this button should vanish, giving way to an audio control window that spans the full width of the screen at the bottom ...

Utilizing Pagination in Python Django to Handle URL Identifiers

I'm encountering a small issue with the following code: Html Code : a href="{% url 'entertainment:novelsView' novel.id %}">buttonclass="pull-right btn btn-primary btn-xs">Link span class="fa fa-link"</span></button</a vi ...

By enabling sorting on the table, the checkbox gets selected automatically

On this particular webpage, I have a unique setup: Users are presented with the option to move items between two tables using sortable functionality. Each table currently holds only one item. The upper table displays tasks assigned to a worker that remai ...

Issue: The variable '$viewMap[...]' is either null or undefined

Unfortunately, my knowledge of jQuery/Javascript is quite limited. I am encountering a Javascript error when trying to change the "how did you hear about us" dropdown on a form. The error message states: Error: '$viewMap[...]' is null or not an ...

How to display currency input in Angular 2

Is there a way to dynamically format input as USD currency while typing? The input should have 2 decimal places and populate from right to left. For example, if I type 54.60 it should display as $0.05 -> $0.54 -> $5.46 -> $54.60. I found this PLUN ...

Is there a way in React JS to attempt a function multiple times using try/catch?

I wrote a function with try catch inside where I make a call to an API for a response. The response returns a Result object with some data. Occasionally, I need to retry the function if certain conditions are met, such as having no name but having a bundle ...

Issue with React-Native 0.68.2 Modals not functioning on iOS platform

After upgrading my react native application to react version 17.0.1 and react-native 0.68.2, the modals are no longer visible on my iOS application. I have been using the react-native-modal: "^13.0.1" library to create these modals. In an attempt to troub ...