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 3356380
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:30:26+00:00 2026-05-18T02:30:26+00:00

I am just experimenting something with jQuery. I have an image which fades into

  • 0

I am just experimenting something with jQuery.

I have an image which fades into another image as mouseOver() occurs and fades back on mouseOut()

It works great, except if you are moving your mouse over the link again and again, say 5 times, the image fades in and out repeatedly, 5 times while you just sit there and wait for it to get over with this crazy behaviour.

To stop this behaviour, I tried to use a flag and start the animation ONLY if it isn’t already animating, but, guess what? If, say, I have 4 such buttons, and on each button mouseover I am fadingIn a different image, that animation will be ignored since the flag is false.

So is there a way to stop all the previous animations before executing new ones?
I am talking about the normal fadeIn() and slideDown() functions in JQuery


EDIT: Adding code from link.

<a href="javascript:void(0);" onMouseOver="mouseOverOut(false);" onMouseOut="mouseOverOut(true);">Tick</a>

JavaScript

function mouseOverOut(t)
{
    if(t)
    {
        $('.img1').fadeIn();
        $('.img2').fadeOut();
    }
    else
    {
        $('.img1').fadeOut();
        $('.img2').fadeIn();
    } 
}
  • 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-18T02:30:27+00:00Added an answer on May 18, 2026 at 2:30 am

    Using .stop() with fadeIn/Out can cause the opacity to get stuck in a partial state.

    One solution is to use .fadeTo() instead, which gives an absolute destination for the opacity.

    function mouseOverOut(t) {
        if(t) {
            $('.img1').stop().fadeTo(400, 1);
            $('.img2').stop().fadeTo(400, 0);
        }
        else {
            $('.img1').stop().fadeTo(400, 0);
            $('.img2').stop().fadeTo(400, 1);
        } 
    }
    

    Here’s a shorter way of writing it.

    function mouseOverOut(t) {
        $('.img1').stop().fadeTo(400, t ? 1 : 0);
        $('.img2').stop().fadeTo(400, t ? 0 : 1);
    }
    

    Or this may work. Test it first, though.

    function mouseOverOut(t) {
        $('.img1').stop().fadeTo(400, t);
        $('.img2').stop().fadeTo(400, !t);
    }
    

    EDIT: This last one seems to work. The true/false is translated to 1/0. You could also use .animate() directly.

    function mouseOverOut(t) {
        $('.img1').stop().animate({opacity: t});
        $('.img2').stop().animate({opacity: !t});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just been experimenting with a CSS tooltip that fades in with CSS3's transitions.
gcc 4.4.4 c89 I was just experimenting with a int array. And something just
I am just starting out in in Emacs. Sometimes I'll be experimenting with something
Just experimenting with different inheritance techniques in JS, and came across something mildly discomfiting
I'm using a PowerPC 750 and have just started experimenting with the external interrupt.
I am experimenting with Java Web Start. I have just written a basic JApplet
I'm just starting experimenting with jQuery and trying to apply it to a very
Since I've been experimenting with jQuery for just a few days now, a few
I've just started experimenting something with Matlab, and since I'm used to Vim's interface,
I have been experimenting with HTML5 and gradient fades, I would like to use

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.