Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:09:15+00:00 2026-05-23T23:09:15+00:00

I am working on a site in which there are a series of elements,

  • 0

I am working on a site in which there are a series of elements, and only one of them must be active at any time. When that element is active, a ‘Details’ div is shown.

These elements become active when you hover on them, but as I said, only one of them can be active at the same time. I am currently setting the active element with an active class.

In my current code, this is what happens when a user hovers on any of the elements:

  • The previous active element gets the class ‘active’ removed , and is fadeOut
  • On the fadeOut callback, the hovered element becomes active (gets the class ‘active’), and is fadeIn
  • If there is no current active element, the hovered element becomes active (class ‘active’) and is fadeIn

This works out OK, but when you hover very quickly between elements, there is a brief moment where no element is active, so more than element gets the active class and is shown.

How would you approach this problem?

Here is my code:

function setActive(selected) {


    //stores the active element in a variable
    active = selected;

    //checks if there are currently elements with the 'active' class in the DOM
    if ( $('#info article.active').length > 0) {

        //if there is any currently active element, and its element_id attribute is not the one stored in the active variable
        //it gets the 'active' class removed, its hidden, and in the callback of the animation
        //the newly selected element gets the class 'active' and is shown with fadeIn

        $('#info article.active[element_id!="' + selected + '"]').removeClass('active').fadeOut('fast', function(){
            $('#info article[element_id="' + selected +'"]').addClass('active').fadeIn('normal');
            }); 

    } else {

        //if there is no current active element, the newly selected one is applied the class active, and shown with fadeIn

        $('#info article[element_id="' + selected +'"]').addClass('active').fadeIn('normal');
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:09:16+00:00Added an answer on May 23, 2026 at 11:09 pm

    Stray (mis)firings on mouse flyovers, and/or finicky targets is a common problem. The standard solution is to have a small delay before a hover “sticks”.

    Important: The question did not show how setActive() was being called!

    But if you structure the HTML something like this:

    <div id="flyOverControls">
        <ul>
            <li rel="Article_1">Show 111</li>
            <li rel="Article_2">Show 222</li>
            <li rel="Article_3">Show 333</li>
            <li rel="Article_4">Show 444</li>
        </ul>
    </div>
    <div id="info">
        <article id="Article_1">First article.</article>
        <article id="Article_2">Second article.</article>
        <article id="Article_3">Third article.</article>
        <article id="Article_4">Fourth article.</article>
    </div>
    

    Then activate the controls like this:

    $("#flyOverControls li").hover (function (zEvent) {setActiveArticle (zEvent); } );
    

    Then this code should do the trick. Adjust speeds to taste. Personally, I’d kill that fade-out.

    function setActiveArticle (zEvent)
    {
        var dDelay;
        var ActionFunction  = null;
        var targetID        = $(zEvent.currentTarget).attr ('rel');
    
        if (zEvent.type == 'mouseenter')
        {
            //--- Hovering over a new article control... Pause for an ergo delay.
            dDelay          = 300;
            ActionFunction  = function (targetID, context) {
                //--- If we are setting the same article, then nothing needs be done here.
                if ( ! (context.lastArticle  &&  context.lastArticle == targetID) ) {
                    //checks if there are currently elements with the 'active' class in the DOM
                    if ( $('#info article.active').length > 0) {
    
                        /*  If there is any currently active element, and its element_id attribute is not the one stored in the
                            active variable it gets the 'active' class removed, it's hidden, and in the callback of the animation
                            the newly selected element gets the class 'active' and is shown with fadeIn.
                        */
                        $('#info article.active').removeClass ('active').fadeOut ('fast', function () {
                            $('#info article#' + targetID).addClass ('active').fadeIn ('normal');
                        } );
    
                    } else {
                        //if there is no current active element, the newly selected one is applied the class active, and shown with fadeIn
    
                        $('#info article#' + targetID).addClass ('active').fadeIn ('normal');
                    }
                    context.lastArticle = targetID;
                }
            };
        }
        else //-- zEvent.type == 'mouseleave'
        {
            //--- Done hovering, no action is needed, other than to wait, in case of user jitter.
            dDelay          = 200;
            ActionFunction  = function (targetID, context) {
                var noOp    = 0;
            };
        }
    
        if (typeof this.delayTimer == "number")
        {
            clearTimeout (this.delayTimer);
        }
        context             = this;
        this.delayTimer     = setTimeout (function() { ActionFunction (targetID, context); }, dDelay);
    }
    

    See it in action at jsFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Wordpress site which has various features that are only available
I'm working on a web site which creates images online ... there is an
I'm working on a new site but there is a small design thing which
I'm working on an MVC 3 site which is hosted in Windows Azure that
I'm working on a web-site which parses coupon sites and lists those coupons. There
I am aware that there are many services which provide geolocation tools for working
I am working on a site which has some Norwegian words. When I used
I'm working on a site which uses the Facebook API to log users in,
I have Drupal 7 site which is working fine. I added a custom PHP
I'm working on a site in which users can opt-in for email notifications for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.