Skip to content

Instantly share code, notes, and snippets.

@davidmars
Last active December 23, 2015 19:19
Show Gist options
  • Save davidmars/6682230 to your computer and use it in GitHub Desktop.
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...
$(".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