calculate on
scrolling on
slow
normal
fast
Source Code
<script type="text/javascript" src="ipnum.js"></script>
<script type="text/javascript">
var Fibonacci = function() {
this.fib1 = new IpNum();
this.fib1.setString('0');
this.fib2 = new IpNum();
this.fib2.setString('1');
this.next = function() {
var x = new IpNum();
x.setArray(this.fib1.getArray());
this.fib1.setArray(this.fib2.getArray());
this.fib2.setArray(this.fib2.add(x).getArray());
return x.getString();
}
}
this.fib = new Fibonacci();
this.delay = 100;
function calcFibonacciLoop() {
var fibonaccis = document.getElementById('fibonaccis');
fibonaccis.appendChild(document.createTextNode(' ' + fib.next()));
calcDelay = setTimeout('calcFibonacciLoop()', this.delay);
}
function calcFibonacciStart() {
var fibonaccis = document.getElementById('fibonaccis');
var spacer = ' ';
if (fib.fib1.getString() == '0') spacer = '';
fibonaccis.appendChild(document.createTextNode(spacer + fib.next()));
var calculate = document.getElementById('calculate');
calculate.href = 'javascript:calcFibonacciStop()';
calculate.firstChild.data = 'calculate on';
scrollFibonacciStart();
calcDelay = setTimeout('calcFibonacciLoop()', this.delay);
}
function calcFibonacciStop() {
clearTimeout(calcDelay);
var calculate = document.getElementById('calculate');
calculate.href = 'javascript:calcFibonacciStart()';
calculate.firstChild.data = 'calculate off';
scrollFibonacciStop();
}
function scrollFibonacciLoop() {
var fibonaccis = document.getElementById('fibonaccis');
fibonaccis.scrollTop = fibonaccis.scrollHeight;
scrollDelay = setTimeout('scrollFibonacciLoop()', 100);
}
function scrollFibonacciStart() {
var scroll = document.getElementById('scroll');
scroll.href = 'javascript:scrollFibonacciStop()';
scroll.firstChild.data = 'scrolling on';
scrollFibonacciLoop();
}
function scrollFibonacciStop() {
clearTimeout(scrollDelay);
var scroll = document.getElementById('scroll');
scroll.href = 'javascript:scrollFibonacciStart()';
scroll.firstChild.data = 'scrolling off';
}
function setDelay(delay) {
this.delay = delay;
}
window.onload = calcFibonacciStart;
</script>
<textarea id="fibonaccis" rows="20"></textarea>
<a id="calculate">calculate on</a>
<a id="scroll">scrolling on</a>
<a id="slowSpeed" href="javascript:setDelay(1000)">slow</a>
<a id="normalSpeed" href="javascript:setDelay(100)">normal</a>
<a id="fastSpeed" href="javascript:setDelay(0)">fast</a>