Last active
December 23, 2015 19:19
-
-
Save davidmars/6682230 to your computer and use it in GitHub Desktop.
.row.auto-clearfix in javascript
In Twitter Bootstrap fmk add .clearfix elements to automatically finish row. Usage: Put a .auto-clearfix css class on a .row element. Call this stuff after resize, on load, put it in a function, etc...
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
$(".row.auto-clearfix").each(function(){ | |
$(this).find(".created-by-auto-clearfix").remove(); //start cleaning previous stuff | |
var prevPos=0; | |
$(this).find(">[class^='col-'],>[class^='span']").each(function(){ | |
var thisPos=$(this).position().left; | |
if(thisPos!=0 && thisPos==prevPos){ //this element should be on a new line dude! | |
$(this).before($("<div class='clearfix created-by-auto-clearfix'>")); | |
} | |
prevPos=$(this).position().left; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment