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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:19:25+00:00 2026-06-05T13:19:25+00:00

var h=0; var w=0; $(.extend).hover(function() { //alert(h); $(this).css({‘z-index’ : ‘999’ }); $(this).addClass(hover).filter(:not(:animated)).stop() .animate({ marginTop:

  • 0
var h=0;
var w=0;
    $(".extend").hover(function() {

        //alert(h);
        $(this).css({'z-index' : '999' });
        $(this).addClass("hover").filter(":not(:animated)").stop()
            .animate({
                marginTop: '-110px', 
                marginLeft: '10px', 
                top: '80%', 
                left: '80%',
                width: 387, 
                height: 487,
                padding: '0px' 
            }, 200);
         h=$(this).height();
         w=$(this).width();
        } , function() {
        $(this).css({'z-index' : '0'});
        $(this).removeClass("hover").stop()
            .animate({
                marginTop: '0', 
                marginLeft: '0',
                top: '0', 
                left: '0', 
                width:w,
                height:h,
                padding: '0px'
            }, 400);
    });

<img class="extend" src="a.jpg">
<img class="extend" src="b.jpg">

I have problem with my hover function i can’t make the image back to original size if i hover it to a.jpg it expand then i hover over to b.jpg without waiting a.jpg to return to original size it will become bigger and bigger.

How i can hover and expand without shifting the size?

  • 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-05T13:19:26+00:00Added an answer on June 5, 2026 at 1:19 pm

    Unless you need your width and height to change, you should only set it once, assuming both images are the same size this should work

    var h=$(".extend").height();
    var w=$(".extend").width();
        $(".extend").hover(function() {
    
            //alert(h);
            $(this).css({'z-index' : '999' });
            $(this).addClass("hover").filter(":not(:animated)").stop()
                .animate({
                    marginTop: '-110px', 
                    marginLeft: '10px', 
                    top: '80%', 
                    left: '80%',
                    width: 387, 
                    height: 487,
                    padding: '0px' 
                }, 200);
            } , function() {
            $(this).css({'z-index' : '0'});
            $(this).removeClass("hover").stop()
                .animate({
                    marginTop: '0', 
                    marginLeft: '0',
                    top: '0', 
                    left: '0', 
                    width:w,
                    height:h,
                    padding: '0px'
                }, 400);
        });
    

    FIDDLE

    EDIT–
    For images with different dimensions save them in the element using .data()

    $(".extend").each(function(){
        $(this).data('width', $(this).width());
        $(this).data('height', $(this).height());
    })
    $(".extend").hover(function() {
    
        //alert(h);
        $(this).css({'z-index' : '999' });
        $(this).addClass("hover").filter(":not(:animated)").stop()
            .animate({
                marginTop: '-110px', 
                marginLeft: '10px', 
                top: '80%', 
                left: '80%',
                width: 387, 
                height: 487,
                padding: '0px' 
            }, 200);
        } , function() {
        $(this).css({'z-index' : '0'});
        $(this).removeClass("hover").stop()
            .animate({
                marginTop: '0', 
                marginLeft: '0',
                top: '0', 
                left: '0', 
                width:$(this).data('width'),
                height:$(this).data('height'),
                padding: '0px'
            }, 400);
    });
    

    FIDDLE

    EDIT-2-
    A simple way to solve the shifting problem is to wrap the img tags in an inline-block element, set the elements dimensions to that of the image then make the img absolutly positioned

    <span><img class="extend" src="a.jpg"></span>
    <span><img class="extend" src="b.jpg"></span>​
    
    $(".extend").each(function(){
        $(this).data('width', $(this).width());
        $(this).data('height', $(this).height());
        $(this).parent().css({display:'inline-block', width: $(this).width(), height: $(this).height()})
        .end().css({position:'absolute'});
    })
    $(".extend").hover(function() {
    
        //alert(h);
        $(this).css({'z-index' : '999' });
        $(this).addClass("hover").filter(":not(:animated)").stop()
            .animate({
                marginTop: '-110px', 
                marginLeft: '10px', 
                top: '80%', 
                left: '80%',
                width: 387, 
                height: 487,
                padding: '0px' 
            }, 200);
        } , function() {
        $(this).css({'z-index' : '0'});
        $(this).removeClass("hover").stop()
            .animate({
                marginTop: '0', 
                marginLeft: '0',
                top: '0', 
                left: '0', 
                width:$(this).data('width'),
                height:$(this).data('height'),
                padding: '0px'
            }, 400);
    });
    

    FIDDLE

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

Sidebar

Related Questions

var A=function(){ }; $.extend(A.prototype, { init:function(){ alert('A init'); } }); var B=function(){ }; $.extend(B.prototype,A.prototype,{
I have simple user model: var user = Backbone.Model.extend({ initialize: function(){ this.bind(change:auth, function (){
Using the following as an example: var Case = Backbone.Model.extend({ initialize: function(){ this.bind(error, function(model,
I have a class: var BrandDrug = Class.extend({ fun1: function() { $.MyFunc(); //This does
this plugin elastic, (function (jQuery) { jQuery.fn.extend({ elastic: function () { var mimics =
var RootComponent = { init: function(options){ options = jQuery.extend({name: 'Root'}, options); this.run('ContainerComponent.init')(options); } }
var homeView = Backbone.View.extend({ el: $(#main_container), initialize: function(){ _.bindAll(this, 'render'); }, render:function(){ $.get('/home', {},
var myView = Backbone.View.extend({ tagName: 'div', className: function() { return this.model.isNew() ? 'new' :
jQuery.fn.daterangepicker = function(settings){ var rangeInput = jQuery(this); //defaults var options = jQuery.extend({ ........ //function
If I have the following: var ObjectA = Ember.Object.extend({ init: function() { this._super(); document.write('init

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.