PX转REM简易计算器(适用于fittext.js插件计算)
当你使用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插件计算)的更多相关文章
- WebSocket最简易理解,term.js插件的使用
介绍WebSocket WebSocket我想大家并不陌生,无论你的的工作中是否用到了它,都或多或少听说过,它是h5中新增的,在某些方面可以很好的替代我们一直沿用的ajax技术,甚至更加的出色.但是它 ...
- Sublime Text中安装插件来实现px与rem间的换算
今天在群里无意中看到了群友分享的一篇关于移动端的文章.里面其他内容我倒不大感兴趣,反而是rem让我提起了兴趣. 首先来谈一下rem,rem是CSS3中新增加的一个单位值,它和em单位一样,都是一个相对 ...
- 使用html+css+js实现简易计算器
使用html+css+js实现简易计算器, 效果图如下: html代码如下: <!DOCTYPE html> <html lang="en"> <he ...
- 用js制作简易计算器及猜随机数字游戏
<!doctype html><html><head> <meta charset="utf-8"> <title>JS ...
- 项目:JS实现简易计算器案例
组件化网页开发下的: 步骤一:让页面动起来的JavaScript深入讲解 的 项目:JS实现简易计算器案例
- 原生JS实现简易计算器
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- JS简易计算器的实现,以及代码的优化
用JS实现简易计算器 首先创建结构和样式 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- js之简易计算器
<!DOCTYPE html PUBLIC "-//W3C//Dli XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JS编写简易计算器
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <head lang=" ...
随机推荐
- nodejs操作 mongoose(mongodb)和Sequelize(mysql)查询数据后添加新属性未生效
最近在着手koa时候,发现mongoose(mongodb)查询数据库后添加新属性,前端拿不到新属性问题, 然后测试了一下Sequelize(mysql),发现也有同样的问题存在.此时着手干! 1.1 ...
- 阿里巴巴开源项目汇总-(JAVA)
来源:https://segmentfault.com/a/1190000017346799 1.分布式应用服务开发的一站式解决方案 Spring Cloud Alibaba Spring Cloud ...
- Applet
Applet简介: 可以翻译为小应用程序,Java Applet就是用Java语言编写的这样的一些小应用程序,它们可以直接嵌入到网页中,并能够产生特殊的效果.包含Applet的网页被称为Java-po ...
- OpenCV3如何使用SIFT和SURF Where did SIFT and SURF go in OpenCV 3?
Installation and Usage If you have previous/other version of OpenCV installed (e.g. cv2 module in th ...
- Laravel 1071 Specified key was too long
出现错误 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key len ...
- erlang并发编程(二)
补充-------erlang并发编程 Pid =spawn(fun()-> do_sth() end). 进程监视: Ref = monitor(process, Pid)靠抛异常来终结进程 ...
- C# Vs2017启动调试,debug或者release调试状态闪一下程序就独立运行了
最近发现一个没太大影响但是很奇怪的事情,编辑状态下点击调试,发现和之前的项目不一样,调试状态闪一下,程序就“独立了”,不受调试状态的控制了. 找了半天才发现,是在program.cs里加了一段代码引起 ...
- JS-构造函数模式代码实战和总结-极客
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 第十六周翻译-SQL Server复制的阶梯:第1级 - SQL Server复制简介
SQL Server复制的阶梯:第1级 - SQL Server复制简介 作者:Sebastian Meine,2012年12月26日 翻译:赖慧芳 译文: 该系列 本文是Stairway系列的一部 ...
- element-ui(或者说Vue的子组件)绑定的方法中传入自定义参数
比如el-upload中的 :on-success= fn,其实是给组件el-upload传递一个prop,这样写的话fn只能接受upload组件规定的参数,如果想自己传递父组件中的参数比如b,要写成 ...