Display information in a box when hovering using CSS and JQuery

I'm looking for an Info-Box (with the code

<div class="inner">...</div>
) that can determine if there is enough space available on the right, left, up, or down to display and adjust accordingly.

While I've managed to check the space on the left and right, I'm struggling to get the box to open on the left side as intended.

When hovering over the 'i' span, the Box should appear, and the z-index of all ".inner" elements will be set to 100 except for the one being hovered over. When leaving the "inner" div container, they will return to their normal z-index.

$(document).on("mouseenter", ".container", function() {
  //height of the document
  let getD = $(document).width();
  console.log(" getD: " + getD);

  //width of the document
  let getDh = $(document).height();
  console.log("getDh: " + getDh);

  //Current offset position
  var offset = $(this).offset();
  console.log("Offset, Left: " + offset.left + " Top: " + offset.top)

  var space_right = getD - offset.left;
  var space_inner = $(".inner").width()
  console.log(space_inner);
  if (space_right >= space_inner) {
    $(".inner").css("z-index", 100);
    $(this).css("z-index", 5000);
    console.log("true");
  } else {
    console.log("false");
  }
});

$(document).on("mouseleave", ".inner", function() {
  $(".inner").css("z-index", 5000);
  $(".container").delay(400)
    .queue(function(next) {
      $(this).css("z-index", 100);
      next();
    })
});
.tabelle-test,
tr,
td,
th {
  border-style: solid;
}

#collapse {
  border-collapse: collapse;
}

.container {
  width: 20px;
  height: 20px;
  position: relative;
}

.inner {
  position: absolute;
  z-index: 5000;
  background: rgb(9, 201, 153);
  padding: 1em;
  border-radius: 10px;
  width: 250px;
  clip-path: circle(5% at 5% 8%);
  transition: all .5s ease-in-out;
  cursor: pointer;
}

.inner>.info_p {
  color: white;
  font-size: .8rem;
}

.inner>.info_span {
  float: left;
  color: white;
  font-weight: bold;
  transition: color .5s;
  position: relative;
  top: -14px;
  left: -4px;
}

.inner>.info_h {
  color: white;
  margin: 0;
}

.inner:hover {
  clip-path: circle(75%);
  z-index: 1000;
  background: #00B6FF;
}

.innen:hover span {
  color: rgba(255, 255, 255, 0)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="tabelle-test" id="collapse">
  <tr width="1020px">
    <th width="1000px">lots of BlaBla</th>
    <th width="20px" height="20px">Info</th>
  </tr>
  <tr>
    <td>blaaaaaaaaa</td>
    <td class="info-td">
      <div class="container">
        <div class="inner">
          <span class="info_span">i</span>
          <h1 class="info_h">Hey</h1>
          <p class="info_p">This is an informative card that will tell you something that's... well, important!</p>
        </div>
      </div>
    </td>
  </tr>
</table>

Answer №1

In the following code snippet, I have made some changes to the CSS classes. The classes have been updated to .inner and .container. There are no adjustments in the jQuery section. If you notice any discrepancies or need further modifications, please inform me.

.tabelle-test,tr,td,th{border-style:solid;}
        #collapse{border-collapse:collapse;}
        .container{width: 100%;height: 20px;position: relative;top: 0;}
        .inner{position:absolute;z-index:5000;background:rgb(9, 201, 153);padding:1em;border-radius:10px;width:250px;clip-path:circle(5% at 93% 8%);transition:all .5s ease-in-out;cursor:pointer;right: -5px;}
        .inner>.info_p{color:white;font-size:.8rem;}
        .inner>.info_span{color:white;font-weight:bold;transition:color .5s;position: absolute;top:1px;right:18px;}
        .inner>.info_h{color:white;margin:0;}
        .inner:hover{clip-path:circle(75%);z-index:1000;background:#00B6FF;}
        .innen:hover span{color:rgba(255, 255, 255, 0)}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="tabelle-test" id="collapse">
        <tr width="1020px">
          <th width="1000px">ganz viel BlaBla</th>
          <th width="20px" height="20px">Info</th>
        </tr>
        <tr>
          <td>blaaaaaaaaa</td>
          <td class="info-td">
            <div class="container">
              <div class="inner">
                <span class="info_span">i</span>
                <h1 class="info_h">Hey</h1>
                <p class="info_p">This is an informative card that will tell you something that's... well, important!</p>
              </div>
            </div>
          </td>
        </tr>
      </table>

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

Ways to retrieve the latitude and longitude coordinates between the starting point and the destination

I need to retrieve all the latitude and longitude coordinates from Google Maps. For instance: If I input the latitudes and longitudes of a source and destination, and a path is drawn on the map like below: Now, I want to obtain all the latitude and longi ...

Mastering the onKeyPress event for Material UI text fields: A step-by-step guide

I have a TextField component from Material UI as shown below: <TextField id="todo-textarea" label="Enter new todo" placeholder="ToDo" onChange={this.props.toDoOnChange} onKeyPress={(ev) => { ...

In Node JS, the variable ID is unable to be accessed outside of the Mongoose

When working with a Mongoose query, I encountered an error where I am trying to assign two different values to the same variable based on the query result. However, I keep getting this error: events.js:187 throw er; // Unhandled 'error' ev ...

Is there a way to verify if the JSON Object array contains a specific value or not?

Hi there! I'm new to JavaScript and I have a question. I need to determine whether the value of an Object is included in a JSON file or not. If it is, then I need to do one thing, otherwise I need to do something else. First, I am retrieving the JSON ...

Transforming a redux form onSubmit function into a promise-based structure

One of my goals is to promisify the onSubmit handling in my submitForm for redux form. You can find a similar example here. submitForm = () => { return this.props.submituserForm() .then(() => { console.log('test') }) ...

Creating a conditional statement in jQuery that will append text to a specific DIV element after a form has been successfully

I currently have a form set up that is functioning properly, but I am looking to make some changes. Instead of redirecting the user to a new page with a success message upon submitting the form, I want the success message to be displayed in a div next to t ...

Guide on extracting unique key values from an array by utilizing a different key

I have an array containing the names of products along with their storage capacities. let products = [{name: "samsung A", storage: "128GB"}, {name: "samsung B", storage: "128GB"}, {name: "samsung C", storag ...

Combining multiple API requests using NodeJS

I'm currently experimenting with SteamAPI to enhance my understanding of NodeJS. My aim is to retrieve game information after making an initial request to obtain the player's profile and storing the game IDs in an array. However, I am facing a ch ...

Eliminate the option to display/hide password icon on Safari

Is there a method to eliminate the show/hide icon in Safari that pops up when entering symbols into an input field with type "password"? I was able to achieve this in IE/Edge by incorporating the following CSS rule: input[type=password]::-ms-reveal, input ...

Challenges related to height

Having an issue with height in my code. My footer is set up like this: <html> <body> <div class='wrap'> <div class=principal></div> <div class='clear'></div> <foo ...

Contrast between PHP and JavaScript output texts

Hey everyone, I'm dealing with a bit of an awkward situation here. I am trying to return a string variable from PHP to JavaScript and use it for a simple comparison in my code. However, the results are not turning out as expected. Initially, I send a ...

Explore the wonders of generating number permutations using JavaScript recursion!

After providing the input of 85 to this function, I noticed that it only returns 85. I am confused as to why it is not recursively calling itself again with 5 as the first number. console.log(PermutationStep(85)); function PermutationStep(num) { var ...

Tips for displaying an array within a table data cell during a while loop

I've encountered this code snippet: $result7 = mysqli_query($conn, $sql7); $resalm = mysqli_query($conn, $contalm); $p = array(); while($row_alm = mysqli_fetch_array($resalm)) { $p[] = $row_alm['nome']; } while($rows_cursos7 = mysqli_fet ...

Navigating through a series of items in VueJS can be easily accomplished by using a

Below is the Vue instance I have created: new Vue({ el: '#app', data: { showPerson: true, persons: [ {id: 1, name: 'Alice'}, {id: 2, name: 'Barbara'}, {id: 3, name: &a ...

Unlocking the potential of data inputted in a JQuery Autocomplete form

Seeking assistance with extracting data from a form to utilize for additional purposes <form onsubmit="return false;"> Enter a School: <input id="schoolsearch" type="text" /> <INPUT TYPE=SUBMIT VALUE="GO"> </form> I am struggling ...

Modifying webpage code

I am looking to develop a system where I can edit various elements such as the navbar, paragraphs, and images directly from a web page. I understand that this can be achieved with JavaScript, but I am facing the issue of my customizations reverting to defa ...

When multiple checkboxes are selected, corresponding form fields should dynamically appear based on the checkboxes selected. I attempted to achieve this functionality using the select option method

Require checkboxes instead of a selection option and have multiple checkbox options. Depending on the checked checkboxes, different form fields should appear. A submit button is needed. I have included some CSS code, but a more detailed CSS code is requir ...

I'm encountering an issue with Material-ui Tabs where clicking submit to go to the next page results in the tab being removed. Does anyone know

I'm facing an issue with my tabs setup. When I click submit, it takes me to the correct page but also removes the tab. How can I prevent this from happening? To better illustrate the problem, I have recreated it in CodeSandbox: https://codesandbox.io ...

Is there a way to delegate properties in Angular 2+ similar to React?

When working with React, I have found it convenient to pass props down dynamically using the spread operator: function SomeComponent(props) { const {takeOutProp, ...restOfProps} = props; return <div {...restOfProps}/>; } Now, I am curious how I ...

Avoiding PHP Execution When Loading From Browser Cache?

One thing I'm trying to understand is how sites like Facebook keep their dynamically generated sidebars, such as the "People you may know," consistent even when users navigate back and forth through their browsing history. On my own site, however, eve ...