View Single Post
Old 07-25-2012, 12:50 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
But I guess if you really wanted to use slice, I'd do it thus:
Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<span onclick="showThree(-1)">left</span>
<p id="test"></p>
<span onclick="showThree(1)">right</span>

<script type="text/javascript">
var imageList = ["obr1.jpg","obr2.jpg","obr3.jpg","obr4.jpg"];
var listSize = imageList.length;

var images = imageList.concat( imageList ); // double the array


var curstart = 0;

function showThree(moveby)
{
    curstart = ( curstart + listSize + moveby ) % listSize;
    document.getElementById("test").innerHTML = images.slice( curstart, curstart + 3 );
}
showThree(0);
</script>

</body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote