在線演示 本地下載
還記得前端時間我們分享的動畫儀表板javascript - gauge.js吧,使用它能夠幫助我們迅速的構建一個超棒的動畫儀表盤效果。
今天這里我們再介紹一款兼容性更好的動畫儀表盤javascript類庫:JustGage,這個類庫基于著名的繪圖類庫Raphaël ,能夠提供更好的繪圖兼容性。
支持瀏覽器
幾乎支持所有的瀏覽器,包括:
IE6+
Chrome
Firefox
Safari
Opera
Android
其它
如何使用
使用非常簡單,首先導入Raphaël和JustGage的類庫,如下:
<script src="js/raphael.2.1.0.min.js"></script>
<script src="js/justgage.1.0.1.min.js"></script>
調用js生成一個新的儀表盤:
var g1 = new JustGage({
id: "g1",
value: getRandomInt(0, 30),
min: 0,
max: 100,
title: "Speedometer",
label: "km/h",
levelColors: [
"#222222",
"#555555",
"#CCCCCC"
]
});
這里調用了一些常用的參數,你可以設置相關儀表盤屬性。
完整代碼如下:
<!doctype html>
<html>
<head>
<title>JustGage Demo By GBin1.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
body {
text-align: center;
font-family: Arial;
}
#g1 {
width:400px; height:320px;
display: inline-block;
margin: 1em;
border: 1px soild #202020;
box-shadow: 0px 0px 15px #101010;
margin-top: 120px;
border-radius: 8px;
}
p {
display: block;
width: 400px;
margin: 2em auto;
text-align: center;
border-top: 1px soild #CCC;
border-bottom: 1px soild #CCC;
background: #333333;
padding:10px 0px;
color: #CCC;
text-shadow: 1px 1px 25px #000000;
border-radius: 0px 0px 5px 5px;
box-shadow: 0px 0px 10px #202020;
}
</style>
<script src="js/raphael.2.1.0.min.js"></script>
<script src="js/justgage.1.0.1.min.js"></script>
<script>
var g1;
window.onload = function(){
var g1 = new JustGage({
id: "g1",
value: getRandomInt(0, 30),
min: 0,
max: 100,
title: "Speedometer",
label: "km/h",
levelColors: [
"#222222",
"#555555",
"#CCCCCC"
]
});
setInterval(function() {
g1.refresh(getRandomInt(80, 100));
}, 800);
};
</script>
</head>
<body>
<div id="g1"></div>
<p> super cool speedometer demo by gbin1.com</p>
</body>
</html>
使用是不是非常簡單,希望大家喜歡這個類庫,如果你有任何問題和建議,請到gbin1.com留言,謝謝!
來源:超棒的儀表盤javascript類庫 - justGage