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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:55:02+00:00 2026-05-22T02:55:02+00:00

I have 9 images arranged in 3 rows. Each row has 3 images. All

  • 0

I have 9 images arranged in 3 rows. Each row has 3 images. All the images are of different size. On hover I am increasing the image width and height to 400px and 300px respectively and on mouseout I am restoring back to their original size. Now the problem is when I hover randomly, images popup but some doesn’t get back to their original size. How do I fix this? Please help.

My code:

jQuery(document).ready(function() {  
        jQuery('my-selector').hover(function() { 
var someVariable = jQuery( 'my-selector img', this );
someVariable.attr('actualWidth', someVariable.width()); 
someVariable.attr('actualHeight', someVariable.height());
jQuery('my-selector').stop()
              .animate({
                width: "400px",             
                height: "300px"
            }, 200, function() {
                // Animation complete.
                jQuery('show-some-div').show();
            });
        },  
 function() {  
jQuery('my-selector').stop()
              .animate({
                width: someVariable.attr('actualWidth'),                
                height: someVariable.attr('actualHeight')}, 200, function() {
                // Animation complete.
                jQuery('show-some-div').hide();
            });
  • 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-22T02:55:02+00:00Added an answer on May 22, 2026 at 2:55 am

    There are actually three potential problems here that I spot.

    The first is that you’re sort of vaguely reselecting your elements when an event fires. This means that even though only one of your images is firing, you’re doing various things to all of them, or else having to do some gymnastics in order to get back to what the user actually interacted with.

    What can help you with this problem is the fact that within a jQuery event callback, the contextual reference variable this will point at the html element that the event refers to. This means that instead of doing

    var someVariable = jQuery('my-selector img', this);
    

    you can do

    var someVariable = jQuery(this);
    

    and it’ll be a jQuery object that points at the html element that fired the event. I like to keep to a convention where jQuery objects start with a $, so I usually do something like

    var $this = $(this);
    

    Regardless, now that you definitely have a reference to the element that actually caused the mouseover or mouseout event, you can use it to do your actions (I’ll stick with someVariable for now):

    someVariable.stop().animate({ ... });
    

    The second problem is that you’re kind of mucking with the DOM when you start attring random attributes onto HTML elements. actualWidth isn’t a real HTML attribute, and some browsers will take more kindly to that fact than others. Thankfully, jQuery provides a way to store off variables that are related to some particular HTML element. Simply use .data rather than .attr exactly the way you’re already using .attr, and it’ll store away the data you want:

    someVariable.data('actualWidth', someVariable.width()); // sets actualWidth
    // ... some time later ....
    var someOtherVariable = someVariable.data('actualWidth'); // gets actualWidth
    

    The third problem I see here is: what happens if someone mouses out of your element, but before it’s returned to its natural size, they mouse back on? Now you’re measuring the image before it’s shrunk back down to its actualSize, and calling that its actualSize. To solve this, simply measure their actualSizes as each one loads (you don’t want to do page load because the images might not yet be loaded, you want to do the load event for each image, and each image will fire its load event when it is loaded and sized):

    jQuery('my-selector img').load(function()
    {
        var someVariable = jQuery(this);
        someVariable.data('actualWidth', someVariable.width());
        someVariable.data('actualHeight', someVariable.height());
    });
    

    Now that you’ve measured each image and stored off what is truly its proper size, you don’t have to do the work each time on mouseover; simply expand the image to 400×300 on mouseover without caring, and then back to the stored off actualWidth and actualHeight when they mouseout.

    Between those three issues, your problem should be nailed.

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

Sidebar

Related Questions

I have about 50 images of 50 x 50 pixel size each. I want
I have images placed in following path res>drawable>Images>Currencies>[All images] I have made a custom
I have images that need to scale to the screen's size. The images will
I have three divs page-left page-right flipper I have images of equal size in
Firstly a short description of what I have Images of the same size and
My android project uses many images, and I have images for different DPIs as
I have a complex background image and images, that should be on exact positions
I have a silverlight control that has a few element such as: Image, TextBox
I have three images inside a div that scale according to window size. The
I have a 2-by-2 grid of images arranged using float property in CSS. I

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.