当你使用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>

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

PX转REM简易计算器(适用于fittext.js插件计算)的更多相关文章

  1. WebSocket最简易理解,term.js插件的使用

    介绍WebSocket WebSocket我想大家并不陌生,无论你的的工作中是否用到了它,都或多或少听说过,它是h5中新增的,在某些方面可以很好的替代我们一直沿用的ajax技术,甚至更加的出色.但是它 ...

  2. Sublime Text中安装插件来实现px与rem间的换算

    今天在群里无意中看到了群友分享的一篇关于移动端的文章.里面其他内容我倒不大感兴趣,反而是rem让我提起了兴趣. 首先来谈一下rem,rem是CSS3中新增加的一个单位值,它和em单位一样,都是一个相对 ...

  3. 使用html+css+js实现简易计算器

    使用html+css+js实现简易计算器, 效果图如下: html代码如下: <!DOCTYPE html> <html lang="en"> <he ...

  4. 用js制作简易计算器及猜随机数字游戏

    <!doctype html><html><head> <meta charset="utf-8"> <title>JS ...

  5. 项目:JS实现简易计算器案例

    组件化网页开发下的: 步骤一:让页面动起来的JavaScript深入讲解  的 项目:JS实现简易计算器案例

  6. 原生JS实现简易计算器

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. JS简易计算器的实现,以及代码的优化

    用JS实现简易计算器 首先创建结构和样式 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  8. js之简易计算器

    <!DOCTYPE html PUBLIC "-//W3C//Dli XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. JS编写简易计算器

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <head lang=" ...

随机推荐

  1. JavaScript Basic Memo

    1.this 的指向 1).由 new 调用?绑定到新创建的对象. 2). 由 call 或者 apply(或者 bind)调用?绑定到指定的对象. 3). 由上下文对象调用?绑定到那个上下文对象. ...

  2. mobike

    1.单向链表的原地反转 public class A { public A next; private int n; public A(int n) { this.n = n; } public st ...

  3. git命令提交新项目

    新建的项目没有与git关联过git initgit add .git commit -m "注释"git remote add origin 新SSH:URLgit push -f ...

  4. .net正则匹配

    char[] weixin = txtweixinhao.Text.Trim().ToCharArray(); for (int i = 0; i < weixin.Length; i++) i ...

  5. C++中_T的用途

    1    C++语言中“_T”是什么意思? Visual C++里边定义字符串的时候,用_T来保证兼容性,VC支持ascii和unicode两种字符类型,用_T可以保证从ascii编码类型转换到uni ...

  6. linux 查看并对外开放端口(防火墙拦截处理)

    [转]https://blog.csdn.net/qq564425/article/details/80760528 Web应用在Tomcat部署后无法访问,可能是防火墙端口限制导致 查看端口是否可访 ...

  7. DevExpress VCL Controls 2019发展路线图(No.3)

    [DevExpress VCL Controls下载] ExpressFlowChart 允许最终用户修改形状(v19.1) 允许开发人员以XML格式定义自定义形状(v19.1) 使用30多个新形状扩 ...

  8. nodejs-POST数据处理

    GET数据:容量小 32K 数据在URL中 POST数据:数据量大 1G 分段传输 数据另外发 处理方法: const http=require("http"); http.cre ...

  9. WPF实现按钮鼠标停留样式的一个坑

    弄了个按钮鼠标停留样式,发现把它应用到某些窗体的Button上会发生样式模糊的问题,而其它窗体又不会. 百思不得其解,真是活久见. 后来发现是跟包着Button的容器控件有关,只要是那些会自适应的容器 ...

  10. Eclipse如何新建TOMCAT并配置Server Locations和Publishing属性

    Eclipse如何新建TOMCAT并配置Server Locations和Publishing属性 2018年05月08日 23:10:33 ACGkaka_ 阅读数:1269   一.建立TOMCA ...