<span onclick="rollPage('down', 200);">Roll DOWN 200 pixels</span> <span onclick="rollPage('up', 200);">Roll UP 200 pixels</span> <span onclick="rollPage('top', 0);">Roll to TOP (roll to the top of the webpage)</span>
<script language="javascript" type="text/javascript"> /* Page roller - this script rolls a webpage up or down; www.virtualsecrets.com */ var rollSpeed = 10; /* Roll recursion speed in milliseconds */ var rollDirection = "down"; /* Roll direction; either "top", "up" or "down" */ var rollAmount = 200; /* Distance, in pixels, to roll */ var rollMovePerIteration = 5; /* Amount, in pixels, to move for each iteration */ var rollYBoundary = 0; /* When rolling down, define the boundary that Y scrolling cannot go beyond; 0 for no boundary */ var rollVal; var rollTrigger = 0, rollCurrent = 0, rollYStartPosition = 0; function rollPage(direction, distance) { if (rollTrigger == 0) { rollTrigger = 1; rollCurrent = 0; rollYStartPosition = 0; rollDirection = direction; rollAmount = distance; /* Determine the current position of the window */ if (document.body) { rollYStartPosition = document.body.scrollTop; } else if (document.documentElement) { rollYStartPosition = document.documentElement.scrollTop; } else { rollYStartPosition = window.pageYOffset; } if (rollYBoundary > 0) { if (rollDirection.toLowerCase() == "down") { if (rollYStartPosition < rollYBoundary) { /* Start rolling */ rollVal = setInterval("rollStep()", rollSpeed); } else { rollTrigger = 0; } } else { /* Start rolling */ rollVal = setInterval("rollStep()", rollSpeed); } } else { /* Start rolling */ rollVal = setInterval("rollStep()", rollSpeed); } } } function rollStep() { rollCurrent = rollCurrent + rollMovePerIteration; if (rollCurrent >= rollAmount && rollDirection.toLowerCase() != "top") { rollTrigger = 0; clearInterval(rollVal); } else { var rollStatus = 1; if (rollDirection.toLowerCase() == "down") { rollYStartPosition = rollYStartPosition + rollMovePerIteration; } else { rollYStartPosition = rollYStartPosition - rollMovePerIteration; } if (rollYStartPosition < 0) { rollYStartPosition = 0; rollTrigger = 0; rollStatus = 0; clearInterval(rollVal); } else { if (rollYBoundary > 0 && rollDirection.toLowerCase() == "down") { if (rollYStartPosition >= rollYBoundary) { rollYStartPosition = 0; rollTrigger = 0; rollStatus = 0; clearInterval(rollVal); } } } if (rollStatus == 1) { window.scrollTo(0, rollYStartPosition); } } } </script>