当你使用fittext.js插件时,通过量取的像素单位PX计算出REM单位值,是一件比较麻烦而繁琐的,为了提高工作效率,自己闲暇写了个小DEMO,现在给大家分享出来。

先看dom:

 <header>
<input type="text" class="fat" placeholder="PX值">
</header>
<div class="box">
<p>8.88888</p>
<ul></ul>
</div>
<footer>
<input type="text" class="son" placeholder="比值">
</footer>

重点js:

<script src="http://apps.bdimg.com/libs/jquery/2.1.2/jquery.min.js"></script>
<script>
$(function(){
$(document).keypress(function (e) {
if (e.keyCode == 13){
var a=$(".fat").val();
var b=$(".son").val();
$(".box p").text(accDiv(a,b).toFixed(5));
$(".fat").val("");
$(".box ul").append('<li><span>'+a+'</span>px:<b>'+accDiv(a,b).toFixed(5)+'</b></li>')
}
})
}); function accDiv(arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
}
catch (e) {
}
try {
t2 = arg2.toString().split(".")[1].length;
}
catch (e) {
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (r1 / r2) * pow(10, t2 - t1);
}
}
</script>

最后是css:

 <style>
*{margin:;padding:;}
body{
background: gray;
}
header{
width: 100%;
background: #000;
height: 100px;
overflow: hidden;
}
header input{
width: 300px;
height: 50px;
text-align: center;
margin: 25px auto;
display: block;
font-size: 40px;
border:;
outline: none;
}
.box{
width: 100%;
height: 800px;
}
.box p{
width: 100%;
height: 200px;
line-height: 200px;
text-align: center;
font-size: 120px;
border-bottom:2px dashed green;
}
.box ul li{
width: 200px;
height: 30px;
float: left;
line-height: 30px;
background: #444;
color: #fff;
margin: 5px 5px;
overflow: hidden;
list-style: none;
font-size: 24px;
}
.box ul li span{
color: red;
width: 60px;
height: 30px;
line-height: 30px;
text-align: center;
display: inline-block;
float: left;
}
.box ul li b{
float: right;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
display: inline-block;
color: #000;
font-weight: normal;
list-style: none;
}
footer{
width: 100%;
height: 100px;
position: fixed;
bottom:;
background: #000;
}
footer input{
width: 300px;
height: 50px;
text-align: center;
margin: 25px auto;
display: block;
font-size: 40px;
border:;
outline: none;
}
</style>

本文系博主原创,转载请注明出处!

最新文章

  1. 深入解析Sqlite的完美替代者,android数据库新王者——Realm
  2. postgresql数据迁移
  3. JS 正则 获取URL参数
  4. 使用接口的方式调用远程服务 ------ 利用动态调用服务,实现.net下类似Dubbo的玩法。
  5. c#串口编程和单片机通信重大发现
  6. mysql登录错误或者密码错误
  7. Enze Second day
  8. Codeforces 451E Devu and Flowers(容斥原理)
  9. oracle导入dmp数据库文件
  10. TForm类有关属性简介
  11. 剑指Offer——知识点储备-故障检测、性能调优与Java类加载机制
  12. Appscanner实验还原code1
  13. 强制不使用“兼容性视图”的HTML代码
  14. 新的开始 接触ASP.NET&#160;Core跨平台的框架
  15. SQL Server T—SQL 存储过程 触发器
  16. Python Django框架笔记(五):模型
  17. 虚拟机中多个Linux系统之间配置免秘钥访问
  18. 【Unity Shader】(四) ------ 纹理之法线纹理、单张纹理及遮罩纹理的实现
  19. [转]ubuntu16.04~qt 5.8无法输入中文
  20. ModelSim+Synplify+Quartus的Alte

热门文章

  1. test--2
  2. 第一次实验报告x
  3. vue-cli axios跨域 + 反向代理模拟http请求host+referer
  4. h5或者微信端吊起app
  5. 小程序获取openid 出现null,{&quot;errcode&quot;:40163,&quot;errmsg&quot;:&quot;code been used, hints: [ req_id: WNUzlA0105th41 ]&quot;}
  6. Altium Designer 使用小技巧2
  7. Android : Camera2/HAL3 框架分析
  8. nginx配置ssl证书
  9. Java NIO学习之Buffer
  10. wifi探针的使用说明.