Creating a persistent hover effect

Utilizing primarily CSS, along with background images and adjacent selectors, I am creating a page that displays unique human-readable text information when the user hovers over horizontally stacked images. The textual information is presented in a div on the left side of the page with the class name "default-text", while the images are on the right side of the page, each uniquely classed with sequentially suffixed classnames such as .hover1, .hover2, through .hover7.

The current functionality works when hovering over the images, but I would like to implement a "sticky" hover state where both the image and accompanying text remain in a hover state even after the cursor moves off them. This state should persist until the cursor hovers over another image or until a specified period of time elapses, let's say 10 seconds.

For example; here's two rows of HTML for the images:

<div class="hover1"></div>
    <div class="hover1text hovertext">
        <h3>Best-in-Class BBQ</h3>
        <p>tons of text</p>
        <p>Lots more awesome text</p>
    </div>
<div class="hover2"></div>
     <div class="hover2text hovertext">
         <h3>Penetration and Vulnerability Tenderloin</h3>
          <p>More awesome text</p>
          <p>What you wanted</p>
      </div>
etc for the balance of the 7 items

A portion from my CSS:

.context-services .region-inner .field-name-body .float-right .hover1 {
    background-image: url(https://dl.dropboxusercontent.com/u/67315586/buttons/1_off.png);
    transition: 0s background;
}
.context-services .region-inner .field-name-body .float-right .hover1:hover {
    background-image: url(https://dl.dropboxusercontent.com/u/67315586/buttons/1_hover.png);
    transition: 0s background;
}
.context-services .region-inner .field-name-body .float-right .hover1 + .hover1text {
    opacity: 0;
    transition: 0s all;
}
.context-services .region-inner .field-name-body .float-right .hover1:hover + .hover1text {
    opacity: 1;
    transition: 0s all;
}

You can view my code on jsfiddle.net here.

I welcome any insights or suggestions. Thank you!

Answer №1

Check out my updated solution, apologies for the lack of transition effects.

(function ($) {

$('.hover1,.hover2,.hover3,.hover4,.hover5,.hover6,.hover7').hover(
function () {
    $('.default-text').hide();
    $(this).addClass('hovered').siblings().removeClass('hovered');
},
function(){
    var self = $(this);
    setTimeout(function(){
        self.removeClass('hovered');
        if (!self.siblings().hasClass('hovered')){
            $('.default-text').show();
        }
    },1000);
});

}(jQuery));

After making this fix, I switched from using CSS hover to adding and removing a 'hovered' class with JavaScript. This allows us to track which elements are hovered over by users.

I replaced the :hover selector with .hovered in the code. When an element is hovered over, we add the 'hovered' class to it and remove that class from its siblings. The mouseout handler waits for 1 second (for testing purposes) before removing the 'hovered' class. If no other tabs are hovered over, the default text is displayed again.

I just noticed a typo - I spelled 'hovered' wrong...please ignore that!

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

IE browser transparency effect on canvas

I have encountered an issue when drawing a shape on canvas using kineticJS and setting the fill to none. The code snippet I am using is below: var rect = new Kinetic.Path({ x: 0, y: 0, data: 'm 2.0012417,2.0057235 ...

Create Event Button for Your Schedule

Looking to create a button that can add events to a calendar using only HTML and CSS, without the need for Javascript. While I've come across similar solutions involving Javascript, I'm specifically focused on finding a solution that doesn't ...

The text is not meticulously arranged within the designated span

My text-align (center) property doesn't seem to be working correctly with the following code snippet: <span class="info">&nbsp;i&nbsp;<span id="uitleg_itje">Bla bla. </span></span> The CSS for the info class is as fo ...

Arranging the Bars in a Bar Chart Using Chart.JS

Lately, I've been playing around with ChartJS and encountering an issue with sorting the bars in descending order, from lowest to highest. Despite my efforts to troubleshoot, I haven't had any success in resolving it. ...

Ways to customize CSS styles for a single page?

<head> <link href="index.css" rel="stylesheet"> <style> #amor_di_mundo{ color:#ffffff; } </style> </head> <body> <div id='divL'> <div id='amor_di_mundo'>Amor di Mundo</div> <di ...

JSON data being sent through an AJAX request

Currently, I am developing a chat system that automatically refreshes using AJAX. Initially, I utilized the jQuery $.post function which worked fine for my needs. However, since I required JSON data from my PHP script, I switched to using the $.ajax functi ...

When using XML, what situations can cause jquery's .attr() and getAttribute() to provide varying results?

When I receive an XML response from a server and parse it in jquery (jQuery 1.8.2 on Chrome 23.0.1271.64 and Firefox 15.01) to retrieve various attributes, it works correctly most of the time. However, occasionally the attr() call returns the entire elemen ...

Unable to view mobile version on HTML page / lack of responsiveness observed

<body> <nav class="navbar navbar transparent"> <div class="container-fluid logo"> <div class="navbar-header"> <a class="navbar-brand" href="#"> <img src="images/Logo.png" /> & ...

Laravel jQuery Issue: Uncaught TypeError - Unable to Access 'value' Property of Undefined

Uncaught TypeError: Cannot read properties of undefined (reading 'value') at $.<computed>.<computed>.menufocus (jquery-ui.js:5911:50) at HTMLUListElement.handlerProxy (jquery-ui.js:626:7) at HTMLUListElement.dispatch (jque ...

Using PHPMailer to send an HTML page via email

I am attempting to email this HTML page using unlayer.com. I have tried using $mail->isHtml(true), ... msgHtml... but the email client keeps showing the code instead of the HTML page. Any suggestions on how to fix this? Here is my code: $sql = "SE ...

Tips for terminating a lingering ajax request and redirecting to a different web page

I am currently in the process of developing an invoice application using object-oriented PHP to create invoice objects with nested objects for customer, product, invoice details, and firm. As I started building a page for an overview, I encountered a prob ...

What is the best way to transfer information from a client's HTML to a node.js server?

I needed to transmit JSON data to a node.js server. Here is my server.js code: var http = require('http'); var util = require('util') http.createServer(function (req, res) { console.log('Request received: '); util.log(util. ...

When resizing the browser window, this single horizontal page website does not re-center

I am in the process of creating my very first one-page horizontal website using jQuery and the scrollTo plugin. This site consists of 3 screens and initially starts in the center (displaying the middle screen). To achieve this, I decided to set the width o ...

What is the best way to display images one by one from a map using a random fade effect?

I am in the process of creating a logo wall for a website. I successfully managed to display them randomly using a map, but now I want to make them appear one by one in a random order (for example: image 1, image 6, image 3, ...) and keep them visible once ...

Working with post metadata in functions.php and making AJAX requests

I may be inexperienced, but I am struggling with this issue. Why is it that when I perform the following: function my_f() { $sss = 'some data'; echo ($sss); die(); } add_action('wp_ajax_nopriv_my_f', 'my_f'); add_acti ...

Create a webpage that utilizes PHP, MySQL, and HTML to load additional content in a way similar to Facebook or the

Seeking guidance on how to incorporate pagination functionality akin to Twitter and Facebook, where a list of items loads initially and then a "load more" button appears below. When clicked, this button appends the list with additional items. Can anyone ...

calculateMinimumTimeBasedOnUserSelectionUsingJQuery

Is there a way to automatically set the minTime based on the user's selection in the FromTime field? In other words, when a user selects a time in the FromTime field, can that same time be used as the preset minTime for the ToTime field? $(' ...

Asynchronous Ajax calls might not be truly asynchronous in frameworks like JQuery and Zend

As I'm working on multiple ajax requests stacked up, here's a snippet of code: $("someTable tr").each(function() { // send the data. var scriptURL = "/module/action/data/" + $(this).find(".data").html() + "/"; document.cyonVars.xhr ...

What is the best way to center text within an input field?

I've been attempting to center the text in the span tag within the input field, but using "text-align": center in my css doesn't seem to be working as expected. Interestingly, when I switched the span tag to a paragraph tag, it caused the input ...

What is the best method for retrieving a child control from a TR element?

I am facing an issue with a hidden field inside each Tr in my template: <ItemTemplate> <tr style="" class="ui-selectee trClass ui-widget-content"> <td style="width: 100px"> <asp:HiddenField ID="idField" runat=" ...