Posts Tagged ‘pictures’

Logical algorithm for previous and next items

Wednesday, July 9th, 2008

This can be used on pictures, news, shop items, etc. with JavaScript events for “previous” and “next”

    if (prev === null) {
      prev = current && next = current + 1
    } elseif (next === null) {
      next = current && prev = current -1
    } else {
      if (action == prev) {
        next = current
        prev = current - 1
      } elseif (action == next) {
        prev = current
        next = current + 1
      } else {
        prev = current - 1
        next = current + 1
      }
    }