Skip to content

Instantly share code, notes, and snippets.

@diegolameira
Last active July 28, 2016 15:00
Show Gist options
  • Save diegolameira/4d622c9e7bb53382a9e8 to your computer and use it in GitHub Desktop.
Save diegolameira/4d622c9e7bb53382a9e8 to your computer and use it in GitHub Desktop.
Just a reference to go back and forth into an array with loop. See it in action: http://run.plnkr.co/plunks/7ngbHx/
var step = 1,
active = 0,
items = new Array();
function next(){
active = (active + step) % items.length;
// active = ++active % items.length;
}
function prev(){
active = (active - step) % items.length;
if ( active < 0 ) active = items.length - Math.abs(active);
// simple for 1 step
// active = active ? --active : items.length - Math.abs(--active);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment