如何为注册表单创建圆形轮廓仪表
How to create a circle shaped profile meter for a registration form
我有一个名为 registration.html 的表单。我想包括一个百分比配置文件仪表。配置文件仪表应根据用户输入的字段更改完成百分比,例如 10%,完成 20% 等。我想使用html,javascript,css来做到这一点。
谢谢
类似于LinkedIn的东西是:
function fillMeter(percent) {
var pixels = (percent/100) * 90;
$(".fill").css('top', (90-pixels) + "px");
$(".fill").css('height', pixels + "px");
}
fillMeter(40);
.fill {
position: absolute;
left: 0;
width: 90px;
background-color: green;
overflow:hidden;
}
.mask {
display: block;
height: 90px;
left: 0;
position: absolute;
top: 0;
width: 90px;
overflow:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="position:relative;">
<div class="fill"></div>
<img class="mask" src="https://static.licdn.com/scds/common/u/img/pic/pic_profile_strength_mask_90x90_v2.png"></img>
</div>
更改55%
等的呼叫fillMeter(55)
百分比。 如下所示:
function fillMeter(percent) {
var pixels = (percent/100) * 90;
$(".fill").css('top', (90-pixels) + "px");
$(".fill").css('height', pixels + "px");
}
fillMeter(55);
.fill {
position: absolute;
left: 0;
width: 90px;
background-color: green;
overflow:hidden;
}
.mask {
display: block;
height: 90px;
left: 0;
position: absolute;
top: 0;
width: 90px;
overflow:hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="position:relative;">
<div class="fill"></div>
<img class="mask" src="https://static.licdn.com/scds/common/u/img/pic/pic_profile_strength_mask_90x90_v2.png"></img>
</div>
工作 JSFiddle: http://jsfiddle.net/5aufgL8o/1/
这是我的答案:
http://cssdeck.com/labs/full/bwxqiw1z
$("#calculate-form").click(function(e) {
// calculate total number of inputs
var numberInputsTotal = $("input").size();
// find all input values that are not empty
var inputsEmpty = $('input:not([value!=""])')
var numberInputsFilled = numberInputsTotal - inputsEmpty.size();
alert(numberInputsFilled);
// calculate width
var width = (100/numberInputsTotal) * numberInputsFilled;
// set width
$("#fill-form .fill").css({'width': width + '%', 'height':'20', 'background': 'red'});
e.preventDefault();
});
width: 100%;
}
#container div#fill-form {
position: relative;
width: 200px;
height: 20px;
border: 1px solid grey;
border-radius: 3px;
margin: 10px;
background: yellow;
}
#container div#fill-form .fill {
display: inline-block;
position: relative;
}
#container div.form {
display: block;
padding: 10px;
}
#container div.calculate {
padding: 10px;
}
#container div.calculate a {
text-decoration: none;
color: #fff;
background: #116adf;
padding: 7px 15px;
border-radius: 3px;
transition: .5s;
}
#container div.calculate a:hover {
opacity: .8;
}
#container label {
width: 100%;
display: block;
margin-bottom: 5px;
}
#container input {
display: block;
}
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<div id="container">
<div id="fill-form">
<div class="fill"></div>
</div>
<div class="form">
<label for="name">Name:</label>
<input name="name" type="text" value="" placeholder="Your Name" />
</div>
<div class="form">
<label for="lastname">Lastname:</label>
<input name="lastname" type="text" value="" placeholder="Your Lastname"/>
</div>
<div class="form">
<label for="email">E-mail:</label>
<input name="email" type="email" value="" placeholder="Your E-mail"/>
</div>
<div class="form">
<label for="username">Username:</label>
<input name="username" type="text" value="" placeholder="Your Username"/>
</div>
<div class="form">
<label for="password">Password:</label>
<input name="password" type="text" value="" placeholder="Your Password"/>
</div>
<div class="calculate">
<a id="calculate-form" href="">Calculate</a>
</div>
</div>
为了获得最佳结果,我建议仅将此处插入的所有代码复制并粘贴到新的html文件中,然后对该文件进行测试。似乎与 SO 集成的代码播放器无法正常运行。
相关文章:
- Highcharts仪表未显示
- 使用外部数据创建仪表板(谷歌电子表格)-JavaScript
- 模板上的每个仪表
- Javascript库创建类似heroku仪表板的应用程序
- 如何改变<仪表>价值观
- Extjs 4仪表图,如何动态更改最大极限值
- JQPlot's仪表-以针为单位显示值
- crm 2011使用javascript在仪表板上隐藏和显示子网格
- Mscrm 2011仪表板通过JavaScript或插件增加行数
- 谷歌图表可视化仪表板数据源问题
- 如何在谷歌仪表板表中为 TR 分配值
- 如何将面板添加到仪表板的特定列中
- 有角度的材料和仪表板
- 使用随机用户生成器创建具有angular.js的轮廓
- 仪表D3.js在指针顶部显示值
- 使用css3在图像上生成轮廓效果
- 仪表板中的小部件和设置需要一个可维护的Javascript回发模式
- 带角度的仪表阵列
- 缩放SVG图像以适应父对象,并在不同的实例中更改仪表颜色
- 如何为注册表单创建圆形轮廓仪表