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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:40:48+00:00 2026-06-13T15:40:48+00:00

I have an image animation problem that I need to fix. When the user

  • 0

I have an image animation problem that I need to fix. When the user hovers over the image, the image should increase in size. When the user moves out from the image, the image should return to its original size.

Problem: When the user moves over and out of the image very quickly, the image will expand and start distort itself, or change to a completely different size. It then continues animating while the mouse is not hovering over the image.

Here is a of the problem JSFiddle

I encountered the same problem using mouseover and mouseout events in the .on() method. Also while chaining those events together in the .on() method

HTML:

<div id="content">
<img id="foo" src="http://www.nasa.gov/images/content/297522main_image_1244_946-710.jpg"  alt="" title="" />

jQuery:

jQuery('#content').on("hover", '#foo', function (e) {
    var $img = jQuery(this);
    var $imgWidth = $img.width();
    var $imgHeight = $img.height();
    var $imgTop = $img.position().top;
    if (e.type == "mouseenter") {
        $img.animate({
            top: $imgTop - 20,
            width: $imgWidth * 1.2,
            height: $imgHeight * 1.2
        }, 200);
    } else if (e.type == "mouseleave") {
        $img.animate({
            top: $imgTop + 20,
            width: $imgWidth / 1.2,
            height: $imgHeight / 1.2
        }, 200);
    }
});
  • 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-06-13T15:40:49+00:00Added an answer on June 13, 2026 at 3:40 pm

    You are getting the width and the height of the image every time you hover over it, even while the image is animating, so the current values aren’t really the ones you want.

    Instead, store the original values and work on those:

    jQuery('img').load(function() {
        var $this = jQuery(this);
    
        $this.data({
            'orig-width': $this.width(),
            'orig-height': $this.height(),
            'orig-top': $this.position().top
        });
    });
    
    jQuery('#content').on("hover", '#foo', function(e) {
        var $this = jQuery(this);
    
        if (e.type == "mouseenter") {
            $this.stop().animate({
                top: $this.data('orig-top') - 20,
                width: $this.data('orig-width') * 1.2,
                height: $this.data('orig-height') * 1.2
            }, 200);
        } else if (e.type == "mouseleave") {
            $this.stop().animate({
                top: $this.data('orig-top'),
                width: $this.data('orig-width'),
                height: $this.data('orig-height')
            }, 200);
        }
    });​
    

    Demo: http://jsfiddle.net/TbDrB/5/

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

Sidebar

Related Questions

I have this simple animation that moves an image from one point to another:
i have a div that it have image content .i wanna implement animation when
I have this code which should create a splash image with either no animation
I have image Array with two images out of that first image its showing
What I have: An absolutely positioned image of a plane that moves across and
I have a problem with my image animation frame. The easiest way to show
I have a Image XML menu that works well, but with a litle problem
i have a script that creates divs with some background image then moves them,
I have a storyboard that animates an image's width. I created the animation with
I have a problem with switching images in android. I want to create animation

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.