Skip to content

Instantly share code, notes, and snippets.

@croucha
Last active March 17, 2016 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save croucha/ac1352ce923dc92fa63a to your computer and use it in GitHub Desktop.
Save croucha/ac1352ce923dc92fa63a to your computer and use it in GitHub Desktop.
/**
* Can set a class to last element in a row of elements floating left.
*
* @param {String} list elements (ul li).
* @param {String}
* @returns {undefined}
*/
var setClassToLastElementInRow = function(selector, className) {
var elements = $(selector);
elements.each(function() {
if($(this).prev().length > 0) {
if($(this).position().top !== $(this).prev().position().top) {
$(this).prev().addClass(className);
}
}
});
};
function calculateListItemsInRow(selector) {
var element = $(selector);
var lisInRow = 0;
element.each(function() {
if($(this).prev().length > 0) {
if($(this).position().top != $(this).prev().position().top) return false;
lisInRow++;
}
else {
lisInRow++;
}
});
console.log('No: of lis in a row = ' + lisInRow);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment