Display or conceal several elements using JQUERY/HTML upon hovering

Here is the current progress:

<div style="position: relative;"> <a href="#games">
    <div class="sidenavOff">
    <img src = "images/card_normal.png" />
    <img src = "images/category_icons/icon_games.png" style = "position: absolute; top: 10px; left: 40px;" />
    <img src = "images/category_titles/title_games.png" style = "position: absolute; top: 160px; left: 40px;" />
    </div>
    <div class = "sidenavOver">
    <img src = "images/hover/card_hover.png" />
    <img src = "images/category_titles/title_games.png" style = "position: absolute; top: 10px; left: 40px;" />
    <img src = "images/hover/card_hover_separator.png" style = "position: absolute; top: 40px; left: 40px;" />
    Display a lot of text here
    <img src = "images/button_start_normal.png" style = "position: absolute; top: 200px; left: 40px;" />
    </div>
    </a>
</div>

The image card.png is essentially a notecard with transparent overlay images. Initially, icon_games.png and title_games.png are displayed on the card when the mouse pointer is away from it. The goal is to show title_games.png, card_hover_separator.png, a text description, and button_start_normal.png in a vertical order whenever the mouse hovers over card.png, icon_games.png, or title_games.png (all within the card area), allowing customization for positioning different from the default display.

This code snippet showcases my attempt at jQuery (inexperienced with it, so likely errors):

$(document).ready(function () {
    $(“div.sidenavOff”).mouseover(function () {
        $(this).removeClass().addClass(“sidenavOver”);
    }).mouseout(function () {
        $(this).removeClass().addClass(“sidenavOff”);
    });
});

Preview without hover effect:

With hover effect:

Answer №1

As previously mentioned, there is no need for JavaScript:

http://jsfiddle.net/arEQy/

.sidenavOver {display:none}
a:hover .sidenavOff {display:none}
a:hover .sidenavOver {display:block}

It is recommended to include class names for the parent elements.

Answer №2

<div class="parent" style="position: relative;"> 
    <a href="#games">
        <div class="sidenavOff">
            <img src = "images/card_normal.png" />
            <img src = "images/category_icons/icon_games.png" style = "position: absolute; top: 10px; left: 40px;" />
            <img src = "images/category_titles/title_games.png" style = "position: absolute; top: 160px; left: 40px;" />
        </div>
        <div class="sidenavOver">
            <img src="images/hover/card_hover.png" />
            <img src="images/category_titles/title_games.png" style="position: absolute; top: 10px; left: 40px;" />
            <img src="images/hover/card_hover_separator.png" style="position: absolute; top: 40px; left: 40px;" />
                 Display a large amount of text here
            <img src="images/button_start_normal.png" style="position: absolute; top: 200px; left: 40px;" />
        </div>
    </a>
</div>

CSS

.parent .sidenavOver {display:none;}

.parent:hover .sidenavOver {display:block;}
.parent:hover .sidenavOff  {display:none;}

There's no requirement for javascript in this case, correct?

Answer №3

It seems like you're looking to switch between different displays when either hovering over the 'off' variation or moving away from the 'Over' variation. You can achieve this with the following jQuery code:

$(document).ready(function () {
    $("div.sidenavOff").mouseover(function () {
        $(this).siblings(".sidenavOver").show();
        $(this).hide();
    })

    $("div.sidenavOver").mouseout(function () {
        $(this).siblings(".sidenavOff").show();
        $(this).hide();
    });
});

Answer №4

To achieve your goal, you can utilize CSS and the hover pseudo-class:

.sidenavOver:hover {
    display:none
}

However, there is a drawback to this method as it may cause flashing when moving your cursor, since :hover does not work when an element is hidden or not displayed.

Another effective approach is suggested by Michael_B, leveraging jQuery's convenient helper functions .show() and .hide().

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

What could be causing the NoScript tag to malfunction across different web browsers?

I've incorporated the NoScript tag into my JSP pages in the head section. To avoid conflicts with tiles, I made sure not to include multiple NoScript tags. However, I am experiencing issues in Internet Explorer where it doesn't seem to be working ...

"Setting the minimum length for multiple auto-complete suggestions in

How can I dynamically set the minLength of an input field based on whether a numeric value is coming from the "#lookup" field? Is there a way to achieve this using JavaScript and jQuery? <script type="text/javascript"> $(document).ready(function() ...

Is there a method to globally import "typings" in Visual Code without having to make changes to every JS file?

Is there a method to streamline the process of inputting reference paths for typings in Visual Studio Code without requiring manual typing? Perhaps by utilizing a configuration file that directs to all typings within the project, eliminating the need to ...

Vue and Jexcel: maximizing efficiency with event handling and dynamic calculations

I am trying to utilize the vue wrapper for jexcel and want to trigger the undo function from the toolbar computed field. However, I am facing difficulties accessing the spreadsheet instance as it throws an error saying 'this.undo is undefined.' ...

The JScrollPane fails to appear during the initial page load

After successfully logging in on my website's login page, I navigate to the second page and encounter an issue where the ScrollBar doesn't show up on first load. I have to refresh the page once more for it to appear. Has anyone else experienced t ...

Creating a user-friendly navigation menu: A step-by-step guide

I need help creating a navigation menu for my website that isn't functioning properly. Here is the code I am currently using: body{ margin: 0px; padding: 0px; } nav > ul{ margin: 0px; padding: 0px; } nav > ul > li{ fl ...

``There seems to be an issue with Firefox's background position percentage

After combining multiple images into one to reduce HTTP requests, I utilized background-position in percentage values to control which image was displayed. Since the width of the images is dictated by the parent element, using percentages rather than pixel ...

Executing a command upon the pressing of the enter key within a text input field

Here is my input field: <input type="text" id="word" /> I am looking for a JavaScript function that will be triggered when the user hits enter in this text box. I searched for an answer but couldn't find one that fits my spe ...

How can I make an HTML button the default option within a form?

Currently, I am working on an asp.net page which contains a mix of asp.net buttons and HTML input[type=button] elements. These HTML buttons are specifically used to initiate AJAX calls. My dilemma arises when the user hits ENTER - instead of defaulting to ...

vue mapGetters not fetching data synchronously

Utilizing vuex for state management in my application, I am implementing one-way binding with my form. <script> import { mapGetters } from 'vuex' import store from 'vuex-store' import DataWidget from '../../../../uiCo ...

Adjust the Material UI card to fill the maximum available height

I'm currently working with Material UI Card components. You can find more information here. My goal is to set a maximum height for these cards, ensuring that the text and images are displayed nicely. How should I approach this? Below is a snippet of ...

Tips for incorporating JavaScript into .ascx pages

What are some ways to incorporate javascript in .ascx files? ...

A guide to importing a Vue component in a JavaScript file

I am looking to achieve a specific behavior in my project: depending on a condition stored in my database, I want to load a particular vue.component instead of another. For example, within a file named discover.js, there is the following code: Vue.compone ...

Parsley JS: A Solution for Distinct IDs

I have a form that contains multiple select boxes, and I need to ensure that no two select boxes have the same value selected. In simpler terms, if select box 1 is set to value 2 and select box 4 is also set to value 2, an error should be triggered. While ...

Mouse over the image link and update the CSS text effect

I need help with a WordPress plugin and I'm trying to avoid making too many changes to the HTML output. Is there a way to make both the image and text change color when hovered over? You can see what I'm working on here - http://jsfiddle.net/3JE ...

The navigation bar on the web app is functioning properly on Android devices but experiencing a CSS problem on

My Nextjs web app includes a navbar with a hamburger menu, logo, and avatar. The navbar functions perfectly on desktop in Chrome, Mozilla, Brave (in developer tools mobile mode), and on Android phones using Chrome. However, when accessed from an iPhone X, ...

Is there a way to ensure my function runs as soon as the page starts loading?

My goal is to have a function execute as soon as a person opens my page, without requiring any interaction. The function should trigger on page load, rather than waiting for a click event. Additionally, I want the function to repeat every 90 seconds. I&apo ...

Array buffers are scheduled by BinaryJs and the Audio API

My node.js server is streaming some ArrayBuffers: var BinaryServer = require('binaryjs').BinaryServer; var fs = require('fs'); var server = BinaryServer({port: 2000}); server.on('connection', function(client){ var file = f ...

Exploring Angular's filtering capabilities and the ngModelChange binding

Currently, I am in the process of working on a project for a hotel. Specifically, I have been focusing on developing a reservation screen where users can input information such as the hotel name, region name, check-in and check-out dates, along with the nu ...

Create a pair of variables by utilizing the split function

I have a string that looks like this test/something/else My goal is to create two separate variables: first = test second = something/else I attempted to achieve this using the following code snippet: const [first, ...second] = "test/something/else& ...