Appear and disappear gradually when hovering

When hovering over #one, the class .hidden is applied to #first. I have added a script to make .hidden fade out using transition: ease-in 0.3s;, but I am having trouble getting the fade in effect to work. I attempted adding transition: ease-in 0.3s; to #first, but it did not solve the issue.

UPDATE Here is the updated code on Fiddle: https://jsfiddle.net/Lbvmgh21/. Upon further testing, I noticed that after triggering the script once (hovering over for the first time), subsequent hovers fade in and out correctly.

$("#one").on({
    mouseover: function () {
        timer = setTimeout(function () {
            $("#first").removeClass('hidden').css('opacity', '1');
        }, 0);
    },
    mouseout: function () {
        clearTimeout(timer);
        $("#first").css({
            'opacity': '0'
        }).addClass('hidden');
    }
});

Answer №1

To achieve the desired effect, place the opacity style within the 'hidden' class in your CSS file instead of using JavaScript. This way, your removeClass and addClass functions will function correctly. Also, consider whether the timer is necessary.

$("#one").on({
    mouseover: function () {
        $("#first").removeClass('hidden');
    },
    mouseout: function () {
        $("#first").addClass('hidden');
    }
});

Answer №2

Have you had a chance to test out this demonstration? Does it seem to be functioning correctly?

Check out the demo here

$(document).ready(function() {
    $("#one").on({
        mouseover: function() {
            timer = setTimeout(function() {
                $(".first").removeClass('hidden').css('opacity', '1');
            }, 0);
        },
        mouseout: function() {
            clearTimeout(timer);
            $(".first").css({
                'opacity': '0',
                'transition': 'ease-in 0.3s'
            }).addClass('hidden');
        }
    });
});

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 a continuous loop in JQuery when clicking on a table row

I seem to be encountering an issue with what appears to be an infinite loop. My problem arises while trying to create a table dynamically using Ajax. Each row of the table contains a button alongside a thumbnail image and some text. I wish for the button ...

Run the jQuery script once it has been successfully loaded using jQuery's .load method

On the Index.html page, there is a select box labeled #choose_content_to_load and a div named #get_loaded_content <select id="choose_content_to_load"> <option>Some content from the page content.html and div #content</option> </select ...

How to position a static element using CSS

I'm trying to align an image in the center of the screen, but I've run into some trouble. Typically, this is easy by setting the width of a div and using margin: auto;. However, I also need the div to have the position: fixed; property, which see ...

Pass Form ID To Function In A Dynamic Way

I have multiple forms on my webpage and I want to use the same ajax function for all of them. It currently works well for one form by fetching the id with getElementById and then passing it to the ajax function. My goal is to dynamically pass down the form ...

Initiating an action the moment the element comes into view by scrolling

I need to apply specific classes to an element with an id of ig-container. The classes I want to add are: $("#ig-container").addClass("animated bounceInRight"); I aim to animate this element once it becomes visible on the screen, triggered by a user scro ...

Unable to get font-face to function properly on IE versions 7 and 8

I'm having trouble getting the font-face to work properly on both IE7 and IE8. This is the code snippet I have used: @font-face { font-family: 'DroidSans'; src: url('fonts/DroidSans.eot'); src: url('fonts/DroidSa ...

submission failure due to unpopulated radio button options

It seems like I'm going crazy... I've got a form with radio buttons, but no matter which one is selected, the POST request only includes the NAME attribute of the radios, not their values: <input type="radio" name="storage" value="1" id="ds_ ...

What is the mechanism through which a flexbox enlarges to accommodate its overflowing child elements?

I am working with a flexbox layout. Here is the HTML code structure: <div class="grid"> <div class="row"> <div class="column">Content</div> <div class="column">Content2</div> <div class="column">Con ...

Data is not returned following an echoed Ajax call

The issue I am currently facing is that the ajax call is successfully updating the record but it is not returning the string of echo as expected. This script was previously functioning without any problems, however, after some sort of upgrade, it seems to ...

Troubleshooting a mysterious anomaly with a jQuery UI button

Would like to achieve something similar to this: http://jqueryui.com/demos/button/#icons When trying to replicate it, http://jsfiddle.net/p5PzU/1/ Why is the height so small? I expected a square shape but am getting a rectangle instead. What could be c ...

Tips on aligning two divs horizontally on the same line

doc.html .column { background-color: orange; width: 75%; vertical-align: top; display: inline-block; height: 200px; } .nav { vertical-align: top; display: inline-block; width: 25%; background-color: lightgreen; height: 200px; } * { ...

The Power of jQuery Dialog Boxes

When the delete button is clicked, I want a dialog box to appear. If 'OK' is clicked in the dialog box, an Ajax call should be made to delete the comment associated with that button. Here is the code snippet: $('.comment-delete').click ...

HTML steps for smooth scrolling to the top and bottom of a list

My HTML contains a vertical list with top and bottom arrows positioned nearby. I am looking to implement a function where clicking on the top arrow will move the list up gradually, and clicking on the bottom arrow will move the list down step by step. Belo ...

Checkbox malfunctioning when trying to add values after being checked

I have successfully completed a calculation system project using JavaScript. Everything works well, the calculations are accurate and taxes are included properly. However, I am facing an issue where the tax is not being included when I click on the checkbo ...

Is there a way to customize my visual studio code to automatically insert an indented space between curly brackets in CSS when I press enter?

Whenever I try to open curly brackets in CSS and press enter, it simply moves to the next line without adding an indentation as shown below: body { } Despite going through the settings and experimenting with different options, I haven't been able to ...

Is there a problem with this spell checking feature implemented with jQuery?

<script type="text/javascript"> // Validate the spelling in a textarea $("#check-textarea").click(function (e) { e.preventDefault(); $(".loading").show(); $("#text-content") .spellChecke ...

Saving sortable portlet items to a database using JQuery AJAX

I've searched through numerous resources to find a solution to my problem, but none of them have been successful. Here is the code I am working with: http://plnkr.co/edit/pcfz33lzHz4wdehjGEuQ I am trying to utilize AJAX to save the order of two port ...

Implement the backstretch plugin method within a jQuery $.ajax call

I am currently working on integrating an Instagram gallery into a responsive Wordpress theme and have encountered some challenges for which I would appreciate assistance. The process involves fetching the Instagram feed using ajax and jsonp, then appendin ...

What is the best way to use a CSS selector to target multiple divs such as block-11, block-12, and so

Here are several block IDs I have: <div id="block-11">content Here</div> <div id="block-12">content Here</div> <div id="block-13">content Here</div> <div id="block-14">conten ...

Responsive menu not functioning properly with jQuery

I am currently working on a website located at . My goal is to incorporate the navigation plugin called MeanMenu into the site. I have followed all the instructions provided in the tutorial: adding the jQuery script to my HTML, including the CSS in the hea ...