-
-
Save Gix075/1e21c4f124df635ee0d1 to your computer and use it in GitHub Desktop.
Get the most highest element height and assigns it to the other elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Version 1.1.0 */ | |
/* ============================== */ | |
function sameHeight(element,assign) { | |
element = (element === undefined || element === "") ? ".HEqualizer" : element; | |
assign = (element === false || element === true) ? element : assign; | |
assign = (assign === undefined || assign === "") ? true : assign; | |
var maxHeight = 0, | |
elementHeight = 0; | |
$(element).each(function(){ | |
elementHeight = $(this).height(); | |
if (elementHeight > maxHeight) { maxHeight = elementHeight } | |
}); | |
if (assign === true) { | |
$(element).height(maxHeight); | |
}else{ | |
return maxHeight; | |
} | |
} | |
/* Version 1.0.0 | |
function sameHeight(element,assign) { | |
var maxHeight = 0, | |
elementHeight = 0; | |
$(element).each(function(){ | |
elementHeight = $(this).height(); | |
if (elementHeight > maxHeight) { maxHeight = elementHeight } | |
}); | |
if (assign === true) { | |
$(element).height(maxHeight); | |
}else{ | |
return maxHeight; | |
} | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
width: 90%; | |
margin: 0 auto; | |
font-family: sans-serif; | |
} | |
.exampleWrapper:before, | |
.exampleWrapper:after { | |
content:""; | |
display: table; | |
clear: both; | |
} | |
.exampleItem { | |
float: left; | |
width: 33.3333%; | |
} | |
.exampleItem p { | |
padding: 10px; | |
border: 1px solid #ccc; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>jQuery Same Height</title> | |
<link rel="stylesheet" href="usageExample.css"> | |
</head> | |
<body> | |
<div class="exampleWrapper"> | |
<div class="exampleItem"> | |
<p>Lorem ipsum dolor si amet, lorem ipsum dolor si amet, lorem ipsum dolor si amet, lorem ipsum dolor si amet, lorem ipsum dolor si amet.</p> | |
</div> | |
<div class="exampleItem"> | |
<p>Lorem ipsum dolor si amet</p> | |
</div> | |
<div class="exampleItem"> | |
<p>Lorem ipsum dolor si amet, lorem ipsum dolor si amet, lorem ipsum dolor si amet.</p> | |
</div> | |
</div> | |
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script> | |
<script src="sameHeight.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment