PX转REM简易计算器(适用于fittext.js插件计算)
2024-10-20 15:52:01
当你使用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>
本文系博主原创,转载请注明出处!
最新文章
- 深入解析Sqlite的完美替代者,android数据库新王者——Realm
- postgresql数据迁移
- JS 正则 获取URL参数
- 使用接口的方式调用远程服务 ------ 利用动态调用服务,实现.net下类似Dubbo的玩法。
- c#串口编程和单片机通信重大发现
- mysql登录错误或者密码错误
- Enze Second day
- Codeforces 451E Devu and Flowers(容斥原理)
- oracle导入dmp数据库文件
- TForm类有关属性简介
- 剑指Offer——知识点储备-故障检测、性能调优与Java类加载机制
- Appscanner实验还原code1
- 强制不使用“兼容性视图”的HTML代码
- 新的开始 接触ASP.NET&#160;Core跨平台的框架
- SQL Server T—SQL 存储过程 触发器
- Python Django框架笔记(五):模型
- 虚拟机中多个Linux系统之间配置免秘钥访问
- 【Unity Shader】(四) ------ 纹理之法线纹理、单张纹理及遮罩纹理的实现
- [转]ubuntu16.04~qt 5.8无法输入中文
- ModelSim+Synplify+Quartus的Alte
热门文章
- test--2
- 第一次实验报告x
- vue-cli axios跨域 + 反向代理模拟http请求host+referer
- h5或者微信端吊起app
- 小程序获取openid 出现null,{";errcode";:40163,";errmsg";:";code been used, hints: [ req_id: WNUzlA0105th41 ]";}
- Altium Designer 使用小技巧2
- Android : Camera2/HAL3 框架分析
- nginx配置ssl证书
- Java NIO学习之Buffer
- wifi探针的使用说明.