Displaying a description div using jQuery when hovering on a box, with the title moving up and down

I'm working on a design where the title of a text and image box is always visible, but the description should only appear when the user hovers over the box. In addition, I want the title and description to be vertically and horizontally centered at all times, regardless of their length. To achieve this effect, I tried using jQuery to measure the height of the title and description text and adjust the visible area accordingly.

For reference, here is an example of the desired effect: (LIFESTYLE & T.E.C.H sections).

Here is my current code implementation:

$(window).load(function(){
  $(".featured-image-box").each(function(){
      var original_title_height = $(this).find(".featured-title").height();
      var original_description_height = $(this).find(".featured-description").height();
      $(this).find(".text-area").css({
        height: original_title_height
      });

        $('.featured-image-box').hover(
            function(){
              $(this).find(".text-area").css({
                height: original_title_height + original_description_height
              })
            },
            function(){
              $(this).find(".text-area").css({
                height: original_title_height
              })
            }
        );

    });

});
.featured-images {
  .featured-image-box {
    background-repeat: no-repeat;
    background-size: cover;
    height: 30vw;
    position: relative;

    ...

</div>

While the current setup partially works, there are issues with the height measurements when hovering over the image and then moving away. Any suggestions or solutions would be greatly appreciated!

Answer №1

For those familiar with jquery-UI, the Tooltip widget offers useful features such as positioning options (check out positioning).

Further information can be found on https://jqueryui.com/tooltip/

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

Creating curved edges in Three.js using Javascript

One of my functions involves creating a track using 3D points from a separate file called trackline.json. The example data in the file looks something like this: [{"x":5.01088018657063,"y":0.033095929202426655,"z":-1.469083126 ...

Troubleshooting issue with MVC Core ASP DatePicker not displaying values after changing local PC date format

Recently, I encountered an issue with my datepicker. Whenever a user enters a value and submits it, the DB gets updated. However, upon refreshing the page, sometimes the value appears and other times it doesn't. This problem arose when I changed my Lo ...

InertiaJS retains form data following validation errors

Within my InertiaJS/VueJS project, I have a prop that receives data from the backend: event: { type: Object, default: () => { return {} } }, This is how the event object looks in the backend: ['name' => 'Event Name'] To m ...

Retrieve RadioButtonList Value using jQuery Function

Here is the code snippet I am working with: <tr> <td> <span>Random question here?</span> </td> <td> <asp:RadioButtonList ID="someList" runat="server" SelectedValue="<%# Bind('someValue') %>" R ...

The boundary of embedded components

I am looking for CSS code that will allow me to arrange all elements with specific indents, such as placing the first element on the left side of the page, followed by an image with some indentation, and so on. <div class="container-fluid"> &l ...

Monitoring the initiation and completion of web requests within the Ionic framework

Currently utilizing the ionic framework in conjunction with Angular JS. In need of assistance on how to monitor the initiation of a web request. To handle the completion of a request, I have created a directive with an onLoad attribute. Here is the exam ...

Error: The function sessions.map cannot be performed

Recently started my journey with Nodejs and I'm following a course on pluralsight to learn more. I encountered an issue while working on the code provided in the course, and now I'm stuck at this point. Error : > TypeError: C:\Users&bsol ...

Only utilize Regular Expressions for character sets

Attempting to solve the puzzle: [fl]ady?[ing] ?[rb]ug!? I believe the solution is: [fl]ad[y]?(ing)? ?[br]ug!? Is it possible to solve this using only character sets? Both words must match. The words are: ladybug fading rug! ...

Unable to display button image when using both id and style class in CSS

During my transition from Java 7 to Java 8, I've encountered a peculiar issue. Here's a brief explanation: In my FXML file, I have a button defined with style class button-red-big and id btnInput: <Button id="btnInput" fx:id="btnInput" align ...

Arrange dynamic elements in rows to utilize the entire available space, while ensuring that groups remain intact and are not split

My form allows users to dynamically add categories, groups, and individual inputs. I want to print the completed form so that it looks good on paper. The form can get quite complex, so I created a separate minimal page for printing purposes. You can view ...

Is it possible to trigger a JavaScript function and an AJAX command with just one button click?

I'm looking to achieve a specific functionality using one button within a form. The requirements are as follows: 1) When the button is clicked, it should trigger a JavaScript function that performs animations such as fadeout and fadein. 2) Following ...

While the file does exist in the current directory, the `readFileSync` function is unable to locate

For my latest SvelteKit project, I was developing a Joke API using Bun as the runtime and TypeScript as the programming language. The goal of this API was to fetch one random dad joke from a text file that contained 363 jokes. Everything was going smoothly ...

Utilizing jQuery or JavaScript to convert a PHP return value into an array for use in JavaScript

Is there a way to retrieve a JavaScript array from a PHP return value? For example, if a PHP script called 'makeArray.php' returns "first", "second", "third" (without the single quotes), how can I use this array in JavaScript to alert "second"? ...

How to utilize the reduce method with an array of objects in JavaScript

Every week, a number of objects are delivered to me. Each object contains information such as date, hours, and other fields. I need to arrange these objects in an array based on the total hours for each day. Here is an example of the objects: var anArray ...

Starting a new layout (activity) from a ListView is a simple process

Whenever the ListView is clicked, I want to initiate a new Activity This is my MainActivity.java package com.theheran.listviewicon; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.View; import a ...

Angular 5's external JavaScript library

After thoroughly researching this subject, I find myself still lacking comprehension. An example may be the key to understanding. As a newcomer to Angular, my goal is to create a mathematical application for mobile using Ionic. Despite investing two weeks ...

What steps should I follow to ensure that the message "Read It" is logged to the console before "Ex It"?

app.get('/', async (req, res) => { await fs.readFile('./views/website/index.html', 'utf8', (err, d) => { data = d console.log("Successfully read the file") // console.log(data) ...

The webpage has finished loading, but capybara is still unable to pass the test

During my automation process, I am checking for the completion of document.readyState === 'complete' and also monitoring a local variable known as window.renderComplete (which indicates when the server has finished rendering the page). However, ...

The onchange event is failing to trigger any JavaScript function

I am facing an issue where the onchange event of a dropdown menu is not triggering at all. I even tried redirecting it to a simple JavaScript function for testing purposes, but that didn't work either. I'm struggling to find a solution. Below is ...

The chosen option from the drop-down menu cannot be shown on the screen

I have developed an application that you can access for testing purposes APPLICATION, but I am encountering some minor issues that I'm struggling to resolve. Despite having correct queries, the selected module is not being displayed in the code sn ...