What is the best way to display a description overlay on an adjacent image when hovering over it?

Seeking assistance or guidance in the right direction.

I have a desire to showcase a grid of images with hover-over functionality for additional information, similar to what can be seen here.

Could someone advise if this task is manageable with pure CSS alone, or would jQuery be necessary? Any pointers in the correct direction would be greatly appreciated.

Answer №1

It appears that the link provided initiates a hover state for the background image followed by displaying a tooltip using a timeOut function. I am currently creating a fiddle to demonstrate this process clearly.


So, without further ado, here is the Fiddle!

The key aspect lies in the jQuery script which incorporates both a delay function and defines the hover state of the image within the CSS code. As a user hovers over the image, an alternate image is displayed initially, achieved through simple CSS hover techniques and the use of CSS sprites.

.item {
    background-color: white;
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-position: center top; 
}

.item:hover {
    background-repeat: no-repeat;
    background-position: center bottom; 
}

#flower {
    background-image: url('http://bramvanroy.be/files/images/tooltipOverlay.jpg');
}

Upon hovering over the image at the outset, a jQuery function is activated with a set delay:

var tooltip = $(".item-tooltip");

tooltip.hide();

$(".item-wrapper").hover(
function() {
    $(this).children(tooltip).delay(550).fadeIn("slow");
    $(this).children(".item").fadeOut("slow");
},
...
​

Exiting the tooltip area triggers its concealment and reveals the original .item image again:

...  
    function(){
        $(this).children(tooltip).fadeOut("fast");
        $(this).children(".item").fadeIn("fast");
    }
);
  • Further information on jQuery's .delay()
  • Additional insights into CSS sprites
  • Image copyright details

ENHANCED RESPONSE:

Presenting a Demo, showcasing the interactive tool, along with another demonstrating the static nature of the image (as requested).

To augment user experience, I implemented the jQuery plugin hoverIntent making sure tooltips are not triggered for unintended quick hovers. This evaluates the user's intent before executing the function after a brief delay. More details about this plugin can be found here. While the standard jQuery hover() method could have been used, it is not recommended.

In addition, adjustments were made to the z-index to prevent overlap issues between the image and the tooltip from different items.

If you have any further inquiries, feel free to ask in the comments section.

Answer №2

To enhance user experience, I recommend utilizing jQuery to achieve the desired effect. Begin by creating two div elements – one visible and one hidden. The hidden div will display information when you hover over the visible div. You can then manipulate the visibility of these divs using jQuery and CSS.

$(".info-class").hover(function(){
    $(this).css('display', 'none');
    $(".other-clas").css('display', 'block');
});

You can implement a similar approach as demonstrated above for a seamless transition.

Answer №3

After reviewing the website, it appears to be overly complex in its design.

If I were to approach this, I would add:

<div class="comtainer">
    <div id="g11" class="square large" data-show-tooltip-in="#g12, #g12">
        <div class="normal-view"><img ... ></div>
        <div class="large-view"><img ... ></div>
        <div class="tooltip">blah blah</div>
    </div>
    <div id="g12" class="square small" data-show-tooltip-in="#g13">
       ...
    </div>
    ...
</div>

In terms of style, you can see:

div.large-view { display : none; }
div.tooltip    { display : none; }

The JavaScript component (using JQuery for efficiency) could look something like:

$( '.square' ).on( 'mouseover', function*(e){
     //hides the normal image
     $( this ).find( '.normal-view' ).hide();
     //shows the zoomed image
     $(this).find('.large-view').show();
     //stores a reference to where the tooltip will be displayed
     var $tooltip = $( $( this ).attr( 'data-show-tooltip-in' ) );
     //hides the original content of the tooltip square
     $tooltip.find( 'div' ).hide();
     //clones and displays the tooltip in the designated area
     $( this ).find( '.tooltip' ).clone().qppendTo( $tooltip ).show();
})

This is just a starting point for the implementation process.

UPDATE explanation provided

The HTML structure consists of multiple div elements with a class of square, each containing necessary data such as normal images, zoomed images, and tooltip HTML. The additional data attribute (data-show-tooltip-in) specifies where the tooltips should appear.

The JavaScript portion takes care of the rest - refer to the comments for guidance.

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

ajax.php form connected to a database using php

Introduction: I am currently working on a server-side datatables library. The code snippet below is not displaying either $stmt or $row, making it difficult to identify the issue. It's frustrating because I was hoping to troubleshoot this without see ...

Showcase big image upon hovering mouse with automatic positioning on Magento

As a newcomer to magento, I am interested in adding an effect that displays a large image when hovering over it with the mouse. This feature should automatically position itself on the product listing page in magento. Your assistance is greatly appreciate ...

Styling trick: Positioning a paragraph next to a span filled with SVG icons

I am facing an issue with the alignment of a set of SVGs contained within a <span> element appearing below a <p> element. I want the span to line up with the text 'Question 1'. Methods I have attempted: No conflicting margins or pa ...

Tips on implementing JSON data into select2 plugin

I have been trying to integrate the select2 plugin into my project. I followed a tutorial from this link, but unfortunately, it's not functioning properly for me. Here is the JSON output: [ {"ime":"BioPlex TM"}, {"ime":"Aegis sym agrilla"}, ...

Is the use of the auto image attribute height/width impacting rendering performance?

Currently, I am facing an issue with setting the height and width attributes for an image as I do not have access to its dimensions from the server. One solution I am considering is setting both the width and height values to auto. For example: img { ...

Enhancing tables with jQuery AJAX

JavaScript function loadData() { var apiUrl = "/api/data"; inputValue=document.getElementById("inputField").value; $.ajax({ type: 'GET', url: apiUrl, data: "&inputValue=" +inputValu ...

What is the best way to generate a specified number of rows with 3 columns in each row using jquery?

After spending 3 hours trying to create a boostrap 'card' with 3 identical cards per row, I unfortunately failed. Here is the code I attempted: $.getJSON("./listings.php", function(e) { $.each(e, function(i, e){ if (e.id != ...

Is there a way to create an HTML select element where each option has a unique background color, and will display properly

I want to create multiple HTML select elements with unique background colors for each option: <select runat="server" id="select"> <option value="A">White</option> <option value="B">Red</option> <option value="C">Yellow& ...

Transferring data to a PHP script using the power of jQuery

Imagine a scenario where there are two links available. <li><a href="#" id="VALUE1" class="charName">Name 1</a></li> <li><a href="#" id="VALUE2" class="charName">Name 2</a></li> Now, when one of these link ...

Utilizing Ajax Blob URL for Audio Streaming

My goal is to retrieve audio data using an Ajax request and load it into an audio element. However, I'm running into an issue where the player does not seem to work properly. The play button remains disabled as if nothing has been loaded. Below is a s ...

Converting strings into the right values through parsing

I have a JSON response that contains multiple suggestions, but I only want to parse and extract the 4 "collation" results: jQuery191029421305245357143_1380819227858( { "responseHeader": { "status": 0, "QTime": 127 }, "command": ...

Arranging Text and Images in HTML/CSS to Ensure Optimal Placement When the Window Size Changes

Hello fellow coders! I've recently started diving into the world of website development and I have a query regarding positioning elements and handling window resizing. Can anyone help me out? I'm trying to center an image, a message, and a passw ...

How can you temporarily delay the original ajax request until a certain condition is satisfied before proceeding?

I'm looking to set up a recaptcha process that intercepts all ajax requests before they are executed - here's how I envision the process unfolding: A user performs an action that triggers an ajax request. If the user has already completed the r ...

"Enhancing Your List Design: Customizing CSS for Hover Effects on Images

I'm currently working on a CSS/HTML list that utilizes an image as the background and changes to a different image when hovered over. However, I've encountered an issue where the hover image is not aligning properly, leaving a noticeable gap. T ...

Is it possible for the HTML data attribute to store a direct link to a specific DOM element?

Can the HTML data- attributes be used to store a reference to another DOM element? As shown in this jQuery example: var domel1 = document.getElementById("#mydiv"); var domel2 = document.getElementById("#mydiv2"); $(domEl1).attr('data-domel', dom ...

Run C# script with the assistance of .load jquery

I have searched extensively for similar posts, but none seem to address the specific question I have regarding my project. What I am attempting to do is load different pages (.aspx) in an iframe dynamically. However, instead of using an iframe, I want to r ...

Creating a jQuery selector that is not case-sensitive

I have a query where I want to ensure it is case-insensitive: var matches = $(this).find('div > span > div#id_to_find[attributeName ^= "filter"]'); if (matches.length > 0) { } Is there a way to make the selector ^= case-insensitive? Pe ...

I'm attempting to pass an array to the ajax load function, but for some reason my controller is not receiving the array correctly

Here is the JQuery code snippet: $(function () { $('#dish-filter-form').on("submit", function (e) { e.preventDefault(); var dishName = encodeURIComponent($('#dishName').val()); var selectFoodType = encodeUR ...

Sending along JSON reply

I have been working on an HTML file that accesses URL1 and successfully parses the JSON response. When I updated my code in the HTML file and called URL2 instead, the flow changed to: Client -> URL2 -> URL1 -> Response to URL2 -> Response to C ...

Is there a way to turn off alerts from Aspx files for HTML and CSS?

Dealing with annoying warnings in my aspx files has been a constant struggle. The "CSS Value is not defined" message pops up when I reference CSS files from different projects, causing unnecessary frustration. Even more frustrating are the warnings about i ...