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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:10:14+00:00 2026-05-25T06:10:14+00:00

need jquery image resize, like if image width > 400 then use resize width:50%,

  • 0

need jquery image resize, like if image width > 400 then use resize width:50%, other images that is smaller size like 100X100 dont need to be resized.

I use this code

var max_size = 400;
$(".comment p.message a.fancy img").each(function(i) {
  if ($(this).height() > $(this).width()) {
    var h = max_size;
    var w = Math.ceil($(this).width() / $(this).height() * max_size);
  } else {
    var w = max_size;
    var h = Math.ceil($(this).height() / $(this).width() * max_size);
  }
  $(this).css({ height: h, width: w });
}); 

But this code dont check smaller images.

  • 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-25T06:10:15+00:00Added an answer on May 25, 2026 at 6:10 am

    Try this: http://jsfiddle.net/aJffu/2/

    var maxsize = 400;
    
    $("#images img").each(function() {
        var t = $(this);
        var maxdim = Math.max(t.width(), t.height());
        if (maxdim > maxsize) {
            t.css({
                width: t.width() / 2,
                height: t.height() / 2
            });
        }
    });
    

    This halves the size of the image if either the width or height exceeds maxsize. Shouldn’t be hard to adapt this to your specific needs. For example, this version scales the image such that the the longest dimension is maxsize.

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

Sidebar

Related Questions

My problem is this: I need to make a JQuery Image slider that resembles
Is there a jquery plugin that allow me to use Marquee on the image
I need a jquery slideshow with div popup i want to show my image
I need to position a div over an image with jQuery. I can create
I need a jquery script section that checks to see if the first digit
Using ASP.NET MVC + jQuery : I need to use some values owned by
I have been using mootools for a year now. I need to use jquery
Is there any jQuery image scroller script similar to this one http://www.eogallery.com/ . Like
I need some jQuery plugin, tutorial or guidelines to create simple image gallery which
I am trying to integrate jquery image slider. But I need to slide the

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.