[原创]纯css模拟液晶式数字显示

首先是借鉴了yiminghe大虾的创意和思路(http://www.iteye.com/topic/705529),可惜看到帖子的时候里面的demo已经打不开了,所以决定自己也做一个。

我觉得他画的数字不好看,所以我还是按照经典样式做的。另外变换数字的原理和思路也他的也不一样,我是全都交给css来完成了,我个人认为渲染效率更高些,实现起来也更简单些。

特点如下:
1,纯css实现,无图片
2,以em为长度单位,支持缩放
3,以不同类名来控制显示数字,方便控制

已知问题:
1,在ff下设为奇数大小时比较杯具,因为ff在计算em长度时四舍五入问题导致棱角与线条会分裂开,ie反到不会。不过这个问题是可以妥善解决的,以后再说了。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title></title>
<style type="text/css" title="">
/*
* Description:
* Author: dragonball
* Create Date:2011-2-22
* Copyright 2011
* Dual licensed under the MIT and GPL licenses.
*/
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td{margin:0;padding:0;}
#mydemo{margin:100px auto;width:600px;}

.clock{font-size:18px;width:9em;height:14em;border:1px solid #ddd;position:relative;}
.clock div{position: absolute;border-style:solid;}
.clock .l,.clock .r,.clock .u,.clock .d{width:0;height:0;overflow:hidden;}

.clock .v{width:0;height:5em;border-width:0 0.5em;border-color:#565656;}
.clock .v .u{border-style:dotted dotted solid dotted;border-width:0 0.5em 0.5em;border-color:transparent transparent #565656 transparent;top:-0.5em;left:-0.5em;}
.clock .v .d{border-style:solid dotted dotted dotted;border-width:0.5em 0.5em 0 0.5em;border-color:#565656 transparent transparent transparent;left:-0.5em;bottom:-0.5em}

.clock .h{width:5.5em;height:0;border-width:0.5em 0;border-color:#565656;}
.clock .h .l{border-style:dotted solid dotted dotted;border-width:0.5em 0.5em 0.5em 0;border-color:transparent #565656 transparent transparent;top:-0.5em;left:-0.5em;}
.clock .h .r{border-style:dotted dotted dotted solid;border-width:0.5em 0 0.5em 0.5em;border-color:transparent transparent transparent #565656;top:-0.5em;right:-0.5em;}

.clock .n1{left:0.5em;top:1.5em;}
.clock .n2{left:0.5em;top:7.5em;}
.clock .n4{left:7.5em;top:7.5em;}
.clock .n5{left:7.5em;top:1.5em;}

.clock .n6{top:0.4em;left:1.8em;}
.clock .n3{top:12.5em;left:1.8em;}
.clock .n7{top:6.5em;left:1.8em;}

.c1 .n1,.c1 .n2,.c1 .n3,.c1 .n6,.c1 .n7{display:none}
.c2 .n1,.c2 .n4{display:none}
.c3 .n1,.c3 .n2{display:none}
.c4 .n2,.c4 .n3,.c4 .n6{display:none}
.c5 .n2,.c5 .n5{display:none}
.c6 .n5{display:none}
.c7 .n1,.c7 .n2,.c7 .n3,.c7 .n7{display:none}
.c8{}
.c9 .n2{display:none}
.c0 .n7{display:none}

</style>
<script type="text/javascript" language="javascript" >
var num=0,size=1;

function addNumber(){
var clock=document.getElementById("mydemo").children[0];
clock.className="clock c"+(++num % 10);
return false;
}

function resize(){
var clock=document.getElementById("mydemo").children[0];
clock.style.fontSize=(++size % 20)+"px";
return false;
}
</script>
</head>

<body>
<div id="mydemo">
<div class="clock c0">

<div class="v n1"><div class="u"></div><div class="d"></div></div>
<div class="v n2"><div class="u"></div><div class="d"></div></div>
<div class="h n3"><div class="l"></div><div class="r"></div></div>
<div class="v n4"><div class="u"></div><div class="d"></div></div>
<div class="v n5"><div class="u"></div><div class="d"></div></div>
<div class="h n6"><div class="l"></div><div class="r"></div></div>
<div class="h n7"><div class="l"></div><div class="r"></div></div>
</div>
</div>

<input type="button" value="改变大小" onclick="resize()" />
<input type="button" value="数字累加" onclick="addNumber()" />
</body>

</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值