![]() There's no need to slice a new array for every iteration.Īn alternate method is to use to shift() to peel off the first item in the array with each iteration: var nextItem = myArray.shift() Note that I've moved the slice() line outside the for loop. Var nextSet = myArray.slice(lastIndex, lastIndex + 2) įor (var i = 0 i ').attr('role', 'menuitem').appendTo('.myList').append('') ![]() ![]() Replace your existing click() with this (including the declaration of lastIndex) to try it: var lastIndex = 0 I don't think there's a way to do exactly what you want, but you can just keep track of where you were in the array and do a slice from there, like this: var nextSet = myArray.slice(lastIndex, lastIndex + 2) Right now it just keeps slicing the same two images because the slicing is not dynamic. ![]() I essentially need to be able to move the start and end index of the slice by (for example) 2 on click. Splitting the array into smaller arrays.Furthermore, I would have to have too many sets of the above to keep slicing 5 out at a time. However, this will not work because images will be continuously added to the gallery. I can of course load, say, 2 at a time: myArray.slice(0,2) ![]() Problem: I cannot figure out how to dynamically slice the array on click (next 5 images). This is in an effort to not load all of the images at once, which could be hundreds. Ideally, I would like to click a button ("Next Set" in the CodePen example) and load the next set (of 2) thumbnail images. The PHP array has been converted/encoded to a JSON array so that I can manipulate the data with JavaScript. I have a photo gallery that includes images that will be continuously uploaded. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |