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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:55:48+00:00 2026-05-25T15:55:48+00:00

I have the following code for a tooltip – it works perfectly in Fx

  • 0

I have the following code for a tooltip – it works perfectly in Fx

http://jsfiddle.net/mplungjan/jkCKh/ (the image used is for demo purposes)

The aim of the code is to not have anything wider or taller than 150 pixels and have it show the original size when mousing over.

var imgUrl = "http://c487397.r97.cf2.rackcdn.com/wp-content/uploads/2011/09/TallCat.jpg";
var idx=1;
var imageObject = $('<img/>').load(function(){
  var w = this.width;
  var h = this.height;
  var orgSize = {width:w,height:h};
  var imgId = "thumb_"+idx;
  var actualImage = $('<img/>')
    .attr("id",imgId)
    .attr("src",imgUrl)
    .addClass("thumb")
    .data("orgSize",orgSize);

  // set EITHER width OR height if either is > 150
  if (w<h && w>150) actualImage.attr("width",150);
  else if (w>h && h > 150) actualImage.attr("height",150);
  $('.qTip2Image').append(actualImage);
}).attr("src",imgUrl);


var cont_left;
$("img.thumb")
 .live("mouseenter",function() {
    // save this scaled down image size for later
    $(this).data("newSize",{width:this.width,height:this.height})
    $(this).animate({
      width: $(this).data("orgSize").width,
      height: $(this).data("orgSize").height,
      left: "-=50",
      top: "-=50"
    }, "fast");
  })
 .live("mouseleave",function() {
    $(this).animate({
      width: $(this).data("newSize").width,
      height: $(this).data("newSize").height,
      left: "+=50",
      top: "+=50"
    }, "fast");
 });

How do I reduce the size identically in most browsers while keeping the aspect ratio?

If the ratio is actually needed to be calculated, please help me by posting an elegant calculation.

  • 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-25T15:55:48+00:00Added an answer on May 25, 2026 at 3:55 pm

    Try setting the height and width using CSS like this:

    actualImage.css("height", 150).
    

    not using the height and width attribute of the img tag. Setting only one of the height or width with CSS should scale the image proportionally. If you have no height and width attributes set on the img tag and you have only one of a height or width set with CSS, then the image will scale proportionally in IE.

    I can get your code to work if I specifically remove the height and width attributes from the image and change your height and width settings to use CSS like this:

    var imgUrl = "http://c487397.r97.cf2.rackcdn.com/wp-content/uploads/2011/09/TallCat.jpg";
    var idx=1;
    var imageObject = $('<img/>').load(function(){
      var w = this.width;
      var h = this.height;
      var orgSize = {width:w,height:h};
      var imgId = "thumb_"+idx;
      var actualImage = $('<img/>')
        .attr("id",imgId)
        .attr("src",imgUrl)
        .addClass("thumb")
        .removeAttr("height")
        .removeAttr("width")
        .data("orgSize",orgSize);
    
      // set EITHER width OR height if either is > 150
      if (w<h && w>150) actualImage.css("width",150);
      else if (w>h && h > 150) actualImage.css("height",150);
      $('.qTip2Image').append(actualImage);
    }).attr("src",imgUrl);
    
    
    var cont_left;
    $("img.thumb")
     .live("mouseenter",function() {
        // save this scaled down image size for later
        $(this).data("newSize",{width:this.width,height:this.height})
        $(this).animate({
          width: $(this).data("orgSize").width,
          height: $(this).data("orgSize").height,
          left: "-=50",
          top: "-=50"
        }, "fast");
      })
     .live("mouseleave",function() {
        $(this).animate({
          width: $(this).data("newSize").width,
          height: $(this).data("newSize").height,
          left: "+=50",
          top: "+=50"
        }, "fast");
     });
    

    You can see it work in IE here: http://jsfiddle.net/jfriend00/jkCKh/7/.

    FYI, it’s also possible to just set both CSS height and width, calculating one from the other to maintain the proper aspect ratio.

    P.S. Dissecting your code, it is a bit bizarre as your essentially loading two copies of the same image. I’m not sure why you don’t just use one image with it’s .load() handler.

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

Sidebar

Related Questions

I have the following code example (see below). My problem is that the tooltip
I have the following code that successfully displays an image in its column based
I have written following xaml code: <Window x:Class=WpfApplication3.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=200 Width=200> <StackPanel>
I have a simple Itemrenderer with the following code: <?xml version=1.0 encoding=utf-8?> <s:ItemRenderer xmlns:fx=http://ns.adobe.com/mxml/2009
i have the following code that does a image rollover on pictureboxes located inside
I have the following code: if (e.Node.Level == 2 && e.Node.Name.Contains(PI3K1003)) toolTip1.Show(test,_tv); It works
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My

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.