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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:40:44+00:00 2026-05-24T05:40:44+00:00

I thought I was being quite clever with this. I’ve made a little function

  • 0

I thought I was being quite clever with this. I’ve made a little function that scales up or down an image to fit with margins within the browser window. With one image it worked great. Then I wanted to do it with several images, so I could click through the images in the same window. I tried using .each, but with little success. It scales up each image based on the dimensions of the first one only. Obviously I want each image to be scaled up depending on it’s own dimensions.

js bit:

$(window).bind("load resize", function(){

    var ww = $(window).width();
    var wh = $(window).height();
    wh = wh-50;
    ww = ww-225;
    var wr = (ww/wh);

    $("#slides div.scale img").each(function(){
        var ow = $("img").width();
        var oh = $("img").height();
        var or = (ow/oh);
        if (wr<or) {
            $("img").css('width',ww);
            $("img").css('height','auto');
        }
        else {
            $("img").css('height',wh);
            $("img").css('width','auto');
        };
    });
});

html bit:

<div id="slides">
    <div class="slide 1 scale"><img src="portrait.jpg" /></div>
    <div class="slide 2 scale"><img src="landscape.jpg" /></div>
    <div class="slide 3 scale"><img src="square.jpg" /></div>
    <div class="slide 4 scale"><img src="portrait.jpg" /></div>
</div>
  • 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-24T05:40:45+00:00Added an answer on May 24, 2026 at 5:40 am
    $("#slides div.scale img").each(function(){
        var ow = $(this).width();
        var oh = $(this).height();
        var or = (ow/oh);
        if (wr<or) {
            $(this).css('width',ww);
            $(this).css('height','auto');
        }
        else {
            $(this).css('height',wh);
            $(this).css('width','auto');
        };
    });
    

    Try that?

    Edit

    I think this needs changed

    function changeimage(){
        $("#slides div").css("visibility","hidden");
        $('#slidetitles span').hide();
        $("#slides div."+ns).css("visibility","visible");
        $("#slidetitles span."+ns).show();
        cs = ns;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I heard that py2exe was able to do this, but I never
I thought this was going to be easy, but it's turning into quite a
I'm a little confused about how to do something that I thought would be
I'm being stymied by what I thought would be the relatively simple task of
I have a problem of web pages being cached even though I specify that
I thought that there was some way in .net 3.0 to give an array
I thought I had seen a bug report about this on the jQuery site,
I thought I'd offer this softball to whomever would like to hit it out
I'm quite new to the whole jQuery/JSON thing but thought I would give it
I am currently optimizing a PHP application and found one function being called around

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.