Last active
March 17, 2016 01:07
-
-
Save croucha/ac1352ce923dc92fa63a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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); | |
} | |
} | |
}); | |
}; |
This file contains hidden or 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
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