justGage-使用按钮增加和减少值 [英] justGage - increase and decrease value with buttons
本文介绍了justGage-使用按钮增加和减少值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用justGage(用于生成和动画化漂亮的仪表盘仪表动画的插件)来对一些图形进行编程-我需要能够通过单击按钮来增大或减小该值.
I'm using justGage (a plugin for generating and animating nice & clean dashboard gauges) to program some graphs - I need to be able to increase and decrease the value by clicking a button.
我可以通过使用refresh(g1.refresh(20);)来做到这一点-但这会使值20 ...不会将其增加20.
I can do this by using refresh (g1.refresh(20);) - but that makes the value 20...it doesn't increase it by 20.
任何人都可以帮忙吗?
非常感谢 铝
推荐答案
我找不到用于检索仪表的当前值的方法,因此我只是将该值存储在一个单独的变量中.然后,每次更新量规时,该变量也是如此.
I couldn't find a method for retrieving the gauge's current value, so I just store that value in a separate variable. Then, every time the gauge is updated, this variable is too.
Demo
<script src="http://cdn.jsdelivr.net/raphael/2.1.2/raphael-min.js"></script>
<script src="http://cdn.jsdelivr.net/justgage/1.0.1/justgage.min.js"></script>
<input type="button" id="inc" onClick="inc()" value="increase by 20" />
<input type="button" id="dec" onClick="dec()" value="decrease by 20" />
<br><br>
amount to change: <input type="text" id="change" />
<br>
<input type="button" id="incVar" onClick="incVar()" value="increase (variable)" />
<input type="button" id="decVar" onClick="decVar()" value="decrese (variable)" />
<div id="gauge" class="200x160px"></div>
<script>
var gageValue = 100;
var g = new JustGage({
id: "gauge",
value: gageValue,
min: 0,
max: 200,
title: "BMI"
});
function updateGage(n) {
g.refresh(gageValue + n);
gageValue += n;
}
function inc() {
updateGage(20);
}
function dec() {
updateGage(-20);
}
function incVar() {
updateGage(parseInt(document.getElementById("change").value))
}
function decVar() {
updateGage(-parseInt(document.getElementById("change").value))
}
</script>
这篇关于justGage-使用按钮增加和减少值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文