When div is clicked, it descends

Is there a way to create an overlay when clicking on the About button, displaying text about the main div? However, I want this overlay to appear over the particles-js div without moving it. The desired effect is a fullscreen overlay with 50% opacity.

$(".about").click(function() {
  $(".main").fadeToggle('500');
  $(".aboutText").fadeToggle('500');
});
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,800');
body {
  background: #1d1d1d;
  font-family: 'Montserrat', sans-serif;
  font-size: 100%;
  margin: 0 auto;
  padding: 0;
  overflow-x: hidden;
}

.container {
  width: 100%;
  margin: 0 auto;
  padding: 0;
}

#particles-js {
  height: 100vh;
  width: 100%;
  background-color: green;
}

#about {
  height: 100vh;
  background-color: beige;
}

h1.main {
  color: white;
  position: absolute;
  padding: 0;
  margin: 0 auto;
  top: 50%;
  display: inline-block;
  left: 50%;
  text-align: center;
  font-size: 4.5em;
  transform: translate(-50%, -50%);
}

h2 {
  color: white;
  position: absolute;
  top: 60%;
  left: 5%;
  font-size: 2em;
}

a.logo {
  text-decoration: none;
  color: #2ecc71;
}

span.home {
  position: absolute;
  top: 50%;
  right: 1%;
  transform: rotate(90deg);
  color: #fff;
  font-size: 1em;
}

a.about {
  position: absolute;
  top: 50%;
  left: 1%;
  transform: rotate(270deg);
  color: #fff;
  font-size: 1em;
}

a.about {
  text-decoration: none;
  color: #fff;
}

@media only screen and (max-width: 500px) {
  .site-nav a {
    padding: 2em;
    font-size: 1.5em;
  }
}

.text {
  color: #fff;
  position: relative;
  top: 50%;
  left: 10%;
  background-color: #000;
  display: none;
}

a.about:hover {
  color: #2ecc71;
}

.aboutText {
  background-color: #000;
  width: 100%;
  height: 100vh;
  background-size: cover;
  opacity: 0.5;
  position: relative;
  display: none;
}

.aboutText--open {
  background-color: #000;
  width: 100%;
  height: 100vh;
  background-size: cover;
  opacity: 0.5;
  position: relative;
}
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta charset="UTF-8">
  <meta name="description" content="Doplniť neskôr">
</head>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="normalize.css">
<body>


  <div class="aboutText">
    <div class="text">
      <p>sssss</p>
    </div>
  </div>
  <div id="particles-js">
    <h1 class="main">Text</h1>
  </div>
  <span class="home">Home</span>
  <a href="#" class="about">About</a>

  <div id="about">

  </div>
  <div id="portfolio"></div>
  <div id="contact"></div>
  <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
  <script src="js/particles.js"></script>
  <script src="app.js"></script>


</body>

</html>

Answer №1

Are you attempting to display the about text when it is clicked on?

$(".about").click(function() {
  $("#particles-js").toggleClass("hide")
  $(".aboutText").toggleClass("hide")  
});
@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,800');
body {
  background: #1d1d1d;
  font-family: 'Montserrat', sans-serif;
  font-size: 100%;
  margin: 0 auto;
  padding: 0;
  overflow-x: hidden;
}

.container {
  width: 100%;
  margin: 0 auto;
  padding: 0;
}

#particles-js {
  height: 100vh;
  width: 100%;
  background-color: green;
}

#about {
  height: 100vh;
  background-color: beige;
}

h1.main {
  color: white;
  position: absolute;
  padding: 0;
  margin: 0 auto;
  top: 50%;
  display: inline-block;
  left: 50%;
  text-align: center;
  font-size: 4.5em;
  transform: translate(-50%, -50%);
}
... (remaining CSS code)
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta charset="UTF-8">
  <meta name="description" content="Doplniť neskôr">
</head>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="normalize.css">

<body>
  <div class="aboutText hide">
    <div class="text">
      <p>sssss</p>
    </div>
  </div>
  <div id="particles-js">
    <h1 class="main">Text</h1>
  </div>
  <span class="home">Home</span>
  <a href="#" class="about">About</a>

  <div id="about">

  </div>
  <div id="portfolio"></div>
  <div id="contact"></div>
  <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
  <script src="js/particles.js"></script>
  <script src="app.js"></script>


</body>

</html>

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

Using jQuery to alter behavior based on the specific id of an element

In my function, I have set it up to display different alerts based on the id when the button is clicked. However, I am facing an issue where the alert displayed does not change even though the id has been updated. $('#loginBtn').on('click ...

Move the button to the following line and center it. Ensure that the background image remains at full size

.home{ background-image:url("https://cdn.pixabay.com/photo/2016/12/27/21/03/lone-tree-1934897_960_720.jpg"); background-repeat: no-repeat; height: 100vh; display: flex; align-items: center; justify-content: center; } .hero-text{ fon ...

What is the method to retrieve the selected value from a drop-down menu that is connected to JSON keys?

I am just starting to learn AngularJS and I need help with binding column names (keys from key-value pairs) to a select list. I want to be able to retrieve the key name when the selection in the select list is changed. The select list displays: name, snip ...

Customizing Geonames JSON Ajax Request

Having found the code I needed from a sample website, I am now seeking help to customize it to only display results from the USA. This is the current code snippet: $(function() { function log( message ) { $( "<div>" ).text( message ).pr ...

Certain computers are experiencing issues with Safari where the sprites background is not resizing correctly

Currently, I am working on a responsive CSS web design project that involves incorporating various sprites for different button states. After testing the website in Firefox, Opera, IE (compatible from IE8), Chrome, and Safari, I have ensured that everythi ...

Is there a method to categorize an array of objects by a specific key and generate a new array of objects based on the grouping in JavaScript?

Suppose I have an array structured like this. It contains objects with different values but the same date. [ { "date": "2020-12-31T18:30:00.000Z", "value": 450 }, { "date": "20 ...

TransitionEnd combining events

Encountered an issue with transitions and transitionEnd when attempting to create slides for a mobile page. $(document).on('click', '#map_view', function () { var lpw = $('.list-page-wrap'), mpw = $('#map_view_page&a ...

What are the best practices for effectively utilizing the nodejs Stream API?

I am currently working on an application that reads input from various sources, including files, sockets, and other parts of the same program that produce buffers or strings. While I have successfully handled sockets and files using node's Stream API ...

How can you create a vertical bar graph using CSS that fills in from the bottom to the top instead of top to bottom?

I have created a bar graph using HTML and CSS. The issue I am facing is that the bar fills up in reverse order - when the height is set to 0%, the bar appears filled at 100%. I attempted changing the CSS property from "top" to "bottom," but it did not reso ...

Utilizing AJAX to showcase an HTML popup

I am currently working on a project to create an HTML page that will display another HTML file in an alert when a button is pressed. However, I am facing an issue where the content is not being displayed as expected. <html> <head> ...

Execute a multer request to upload an image (using javascript and express)

I am utilizing the Express server as an API gateway for my microservices, specifically to process and store images in a database. The issue at hand is that within the Express server, I need to forward an image received through a POST request from the clien ...

Using a JavaScript script in my HTML alongside Vue.js is not possible

Hello there! I recently created a Node.js server and now I'm trying to display an HTML file that contains a Vue script which loads data using another method written in a separate JS file. However, when I attempt to load my HTML file in the browser, ...

Troubleshooting: Error message when using getElementById in JavaScript

Issue: While creating a simple demo site to experiment with JavaScript, I encountered a "TypeError: document.getElementById(...) is null" when attempting to change the display value of an element to block upon button click. Despite trying common solution ...

Exploring the Functionality of Drag and Drop with JPG and GIF in Internet Explorer 9/10/11

When trying to drag, drop, or select a file using a form in Internet Explorer 9/10/11, only JPEG and PNG files are accepted, while JPG and GIF extensions are rejected. This issue is present in both the code I am using below and in the demo found at https:/ ...

Why is my jQuery .closest() function not functioning correctly following an AJAX request?

The issue I'm facing involves removing a div after making an AJAX call. For some reason, the .closest() function is not behaving as expected. From my understanding, it should climb up until it finds a matching element. <div class="comments"> ...

What is the correct placement of DESC in a MySQL query when using PHP?

Here's the issue I'm facing: $query = "SELECT * FROM table ORDER BY 'timestamp' LIMIT $startAt, $perPage"; I've been attempting to sort the results in descending order (latest on top) by adding DESC to the query. However, every t ...

Loading JQuery dynamically from an externally linked JavaScript file

Our clients can easily add a short script to their website to load our application. This script asynchronously loads the JavaScript that triggers the application on the client's page, typically as a pop-up. The launch code for the application requires ...

Using jQuery to select a nested element in HTML

After choosing $("a.tp[programm='" + programm + "']"); I am looking to target the nested element span.thump and update its text content. How can I achieve this? <h4><a programm="74" class="tp" href="#"><img src="/images/tuo.png ...

Sublime snippet for Jquery $(document).ready() fails to activate

I recently created a custom snippet in Sublime Text for the jQuery document ready function. However, I am experiencing an issue where the tab trigger appears in a popup but when I press enter or tab, no code is generated. Even after restarting Sublime mult ...

Is it possible to bind browser keyboard scrolling to a div without explicit instructions?

Here is a question that closely relates to this one: Enable div to scroll by keyboard without clicking I am aware that explicitly focusing on the element will enable the desired behavior. My inquiry is whether there is a way to achieve this implicitly. ...