Created
August 13, 2013 00:50
-
-
Save sortofsleepy/6216833 to your computer and use it in GitHub Desktop.
In a list of items, this figures out where then end of a row is at any particular given time. 1. box_width = the width of a item in the list
2. work_width = the width of the container for the list
This file contains 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
/* | |
Based on the item you click on, this function | |
figures out the ending index of that particular item's row. | |
*/ | |
function getRow(index){ | |
//this is the number of items that can fit in a row | |
var row = Math.floor(box_width / work_width); | |
//var insertpoint = index + row; | |
//this is the number of rows that the contents go vertically | |
var v_row = Math.floor(parseInt(works[0].style.height) / work_height); | |
// figure out which indicies mark the end of a row, this will | |
// be the index to insert the "open" view for a item | |
var ends = []; | |
for(var i = 0;i<v_row;++i){ | |
ends.push(((row * i) + row) -1 ); | |
} | |
//get the row we clicked on(Just take the first indice | |
var possible = []; | |
//now figure out what row we're on. | |
for(var a = 0;a<ends.length;++a){ | |
if(index < ends[a]){ | |
possible.push(a+=1); | |
}else if(index == ends[a]){ | |
return ends[a]; | |
} | |
} | |
var end = ends[possible[0]-1]; | |
return end; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment