Solved

jquery find the smallest image in a row

Posted on 2014-10-27
3
330 Views
Last Modified: 2014-10-28
Hello Experts,

I am trying to determine the smallest image (height)  in a row of images.
Then I am setting the images container to the smallest image.

So basically i am doing this as a responsive solution keeping the all the images in a row at the same height using the images container height and overflow hidden.

Here is a script i found online and i was trying to play with it yet it seems that it does not work.

Can someone take a look?

var allImages = $('.images');
var imageSmallest = allImages[0];
		
$(allImages).each(function() {

      if ($(this).height() < $(imageSmallest).height()) 
              imageSmallest = $(this);
			 
      var imageSmallestHeight = imageSmallest.height();
     $('.images-container').css("height" , imageSmallestHeight);
});	

Open in new window

0
Comment
Question by:Refael
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40407520
so post a link to your page, the script look fine
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40407622
Here's something I use adapted to your scenario
minH = Math.min.apply(Math, $('.some_image_class').map(function() {
	return $(this).height();
}).get());

Open in new window


minH will be the smallest height of all the images, then you need to apply that to your images

$(".some_image_class").css("height", minH)
0
 

Author Closing Comment

by:Refael
ID: 40408209
Gary, thank you. It works like a magic :-)
Just wondering what was wrong in my script?

Also thank you leakim971 for trying :-))

You both guys are the best!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question