IrDewey
07-28-2008, 03:38 AM
HTML:
<form name=f>
<input name="t">
<input type=button value="Deplete" onclick="deplete(document.f.t.value)">
<input type=button value="Restore" onclick="restore(document.f.t.value)">
</form>
<div style="width: 250; height:15; border: solid; background-color: darkred">
<span id="s"></span>
</div>
<div style="width: 250; height: 15; margin-top:-20">
<span id="a"></span>
</div>
Javascript:
document.getElementById("s").innerHTML = '<div style="background-color:red;height:15;width:0;"></div>'
document.getElementById("a").innerHTML = '<center><b>0</b></center>'
var value = 0 //Displayed value, used in animate() as an "after" value
var v = 0 //Used in animate() as a "before" value
function deplete(x){
v = value
if(x >= 0){
value -= x
if(value < 0){
value = 0
}
}else{
alert("Number must be greater than zero")
return
}
return animate()
}
function restore(x){
var v = value
if(x >= 0){
value -= -x
if(value > 100){
value = 100
}
}else{
alert("Number must be greater than zero")
return
}
return animate()
}
function animate(){
if(v == value){
return
}else{
if(v < value){
v -= -1
}
if(v > value){
v -= 1
}
l = v * 2.5
document.getElementById("s").innerHTML = '<div style="background-color:red;height:15;width:'
+ l
+ ';">'
+ '</div>'
document.getElementById("a").innerHTML = '<center>'
+ '<b>'
+ v
+ '</b>'
+ '</center>'
}
setTimeout("animate()",50)
}
Script which displays a bar, indicating a given value. The way I scripted it, 100% means a 250px bar, however you could easily change that to be whatever you want...
The HTML displays a text box followed by "Deplete" and "Restore" buttons. The deplete(x) and restore(x) functions add or subtract from the current value to get a new value, then goes to the animate() function to change the length of the bar.
This script can be adapted for many different uses, use your imagination.
HTML displays correctly in Firefox, and Opera, but not in IE (Just DIV issues, nothing major).
Enjoy :)
<form name=f>
<input name="t">
<input type=button value="Deplete" onclick="deplete(document.f.t.value)">
<input type=button value="Restore" onclick="restore(document.f.t.value)">
</form>
<div style="width: 250; height:15; border: solid; background-color: darkred">
<span id="s"></span>
</div>
<div style="width: 250; height: 15; margin-top:-20">
<span id="a"></span>
</div>
Javascript:
document.getElementById("s").innerHTML = '<div style="background-color:red;height:15;width:0;"></div>'
document.getElementById("a").innerHTML = '<center><b>0</b></center>'
var value = 0 //Displayed value, used in animate() as an "after" value
var v = 0 //Used in animate() as a "before" value
function deplete(x){
v = value
if(x >= 0){
value -= x
if(value < 0){
value = 0
}
}else{
alert("Number must be greater than zero")
return
}
return animate()
}
function restore(x){
var v = value
if(x >= 0){
value -= -x
if(value > 100){
value = 100
}
}else{
alert("Number must be greater than zero")
return
}
return animate()
}
function animate(){
if(v == value){
return
}else{
if(v < value){
v -= -1
}
if(v > value){
v -= 1
}
l = v * 2.5
document.getElementById("s").innerHTML = '<div style="background-color:red;height:15;width:'
+ l
+ ';">'
+ '</div>'
document.getElementById("a").innerHTML = '<center>'
+ '<b>'
+ v
+ '</b>'
+ '</center>'
}
setTimeout("animate()",50)
}
Script which displays a bar, indicating a given value. The way I scripted it, 100% means a 250px bar, however you could easily change that to be whatever you want...
The HTML displays a text box followed by "Deplete" and "Restore" buttons. The deplete(x) and restore(x) functions add or subtract from the current value to get a new value, then goes to the animate() function to change the length of the bar.
This script can be adapted for many different uses, use your imagination.
HTML displays correctly in Firefox, and Opera, but not in IE (Just DIV issues, nothing major).
Enjoy :)