user2888784 user2888784 - 5 months ago 9
Javascript Question

Is there a way to pause a loop until a user swipes right or left?

I need a simple way to pause my while loop until the user swipes left. Right now my while loop runs through all my objects without giving them a chance to display, so that only the last one ends up displaying. What I'm looking for is something that will let my function run once and wait until a user swipes right or left before going through the while loop again.
Any help in the right direction would be greatly appreciated. Google has not yet returned what I want.


It's hard to understand exactly what you want, but the way it sounds, you want a swipe to run through the loop once and stop until you swipe again. What you can do is eliminate the while loop and just keep track of the steps through your array of objects. Something like (very rudimentary, but will give you a general idea):

// hold onto your position (the item currently displayed) in the module
var objIndex = 0;

// when you swipe to the next, increment the index and display the next item you fetched from the api
function moveNext() {
    objIndex += 1;
// if you can go backwards with a swipe, decrement the index and display the previous item you fetched from the db
function movePrev() {
    objIndex -= 1;

function displayData() {
    // your code to display your item on screen using the index you've saved in the module