I am using a function to equalise the height of li tags returned from a database. I am also using jquery to assign certain li new classes dependant on their position in a row.
Basocally my problem is that the positioning part of the jquery statement always works but the equal heights part will sometimes not fire, in fact it generally doesn't work on an empty cache - it will however always fire on refresh or second visit to the page.
Live example here Link here!(let me know if it works for you!)
The jquery code I am using is listed below.
jQuery.fn.equalCols = function(){
//Array Sorter
var sortNumber = function(a,b){return b - a;};
var heights = [];
//Push each height into an array
$(this).each(function(){
heights.push($(this).height());
});
heights.sort(sortNumber);
var maxHeight = heights[0];
return this.each(function(){
//Set each column to the max height
$(this).css({'height': maxHeight});
});
};
jQuery(document).ready(function($) {
$(".thumbs").each(function(i) {
if (i % 4 == 0)
$(this).addClass("start");
if (i % 4 == 3)
$(this).addClass("end");
});
$(".thumbs").each(function(i) {
if (i % 3 == 0)
$(this).addClass("start");
if (i % 3 == 2)
$(this).addClass("end");
});
$(".event_thumbs").each(function(i) {
if (i % 2 == 0)
$(this).addClass("start");
});
$('.thumbs, .end, .start').equalCols();
});
If you have an better suggestions for the code or methods to achieve the aim please shout out or if you know how to make it work - I love you.