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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:55:33+00:00 2026-06-09T13:55:33+00:00

I’ve just noticed that at some stage Chrome has updated to a new version

  • 0

I’ve just noticed that at some stage Chrome has updated to a new version and some of my jQuery code no longer works… (jQuery version 1.7 – bundled with wordpress)

This is basic code for positioning images (centring) in a slide show and positioning the previous / next buttons.
It works in FF (don’t know about IE – I look at that as little as possible). What it now does in chrome, instead of doing the calculation of height of box minus height of image, is to simply divide the box height by two. So, whereas for a box 4x high with an image 2x high FF gives me the correct “top: 1x”, Chrome gives me “top:2x”.

Strangely it positions the #next and #prev divs correctly…

h = j$('.slide').height();
w = j$('.slide').width();
nph = j$('#next').height();
j$('.slide').each(function(){
   thisImg= j$(this).find('img');
   var imgH = thisImg.height();
   var imgW = thisImg.width();
   thisImg.css({'position':'absolute',
               'top':(h-imgH)/2,
               'left':(w-imgW)/2
   } );
}) ;
j$('#next, #prev').css('top',(h-nph)/2);

};

Either I’m not doing something correctly, or something has changed in chrome (I’ve lost a complete animation on another site since the update).
If I’m not at fault, what hack is there for Chrome?

EDIT Further research leads me to think it is because I am trying to use images in a flexible (percentage based) environment.
This means the image and the div are styled thus :

div {height:100%;width:100%;}
img {max-height:100%;max-width:100%}

It seems that Firefox can make the calculation, but Chrome can’t. The “next” and “prev” divs have known dimensions (and position correctly) Is there a way of “catching” the image as it is loaded and finding out what it’s dimensions are before max-height and max-width are applied ?

FURTHER UPDATE
I have managed to confirm that Chrome cannot return the value of the height of an image on the page if it’s styled “max-height” or “max-width”. Nor does the “outerHeight/Width” method work.

  • 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-09T13:55:35+00:00Added an answer on June 9, 2026 at 1:55 pm

    Nick, I think the workaround is to apply the max-height and max-width limits in javascript rather than CSS with the added advantage of allowing the images’ aspect-ratio to be maintained. The CSS does not have this feature as it applies the height and width limits independently.

    Applying the limits can be done in the same loop that applies the ‘left’ and ‘top’ offsets.

    Try this:

    j$(function() {
        j$(".slide img").each(function(i, img) {
            var $img = j$(img),
                $wrapper = $img.closest(".slide"),//assuming '.slide' is the constraining wrapper
                w = $wrapper.width(),
                h = $wrapper.height(),
                _w = $img.width(),
                _h = $img.height(),
                scale = Math.min(1, w/_w, h/_h);//scale down if necessary, never scale up, preserving aspect ratio
            _w *= scale;
            _h *= scale;
            $img.width(_w).height(_h).css({
                'position': 'absolute',
                'left': ( w - _w ) / 2,
                'top': ( h - _h ) / 2
            });
        });
        var nph = j$('#next').height();
        j$('#next, #prev').css('top', (h-nph)/2);
    });
    

    As indicated in the comment, I had to assume that .slide is the constraining wrapper. If not, then adjust the selector in the statement $wrapper = $img.closest(".slide").

    Don’t worry about Math.min(), it’s not a mistake. Taking a minimum , applies a maximum.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.