当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 用js实现的抽象CSS圆角效果!!

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 用js实现的抽象CSS圆角效果!!


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 81 ::
收藏到网摘: n/a

大概是去年的时候吧,就在网上见过了现成的CSS圆角效果的CSS及HTML代码,例如:

<html>
<head>
<title>css圆角效果</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
div.RoundedCorner{background: #9BD1FA}
b.rtop, b.rbottom{display:block;background: #FFF}
b.rtop b, b.rbottom b{display:block;height: 1px;overflow: hidden; background: #9BD1FA}
b.r1{margin: 0 5px}
b.r2{margin: 0 3px}
b.r3{margin: 0 2px}
b.rtop b.r4, b.rbottom b.r4{margin: 0 1px;height: 2px}
</style>
</head>
<body>
<div class="RoundedCorner">
<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
1
<b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>
</div>
</body>
</html>

当然这样人为的把圆角值设置好,也非常好用了,基本上这段代码拿过去就可以用,但是如果要改变这个圆角的大小,要在这个角上加边框或基它的效果,那这段代码拿来就发挥不了它的威力了.就想做一个抽像化的组件化的东西出来!今年可谓是花费了几乎一天的时间!
想一想,圆角的四个角加在一起正好是一个圆,而圆的表达式是x*x+y*y=r*r,即x的平方加上y的平方等于半径的平方!有了这个公式,那么实现圆解的理论就得以角决了!
开始一步步的测试由没有到有,由零难化到组件化吧!我把一个圆角实现分为这样的结构
[顶部][顶部圆角显示控制][/顶部]
[主体][主体左边显示圆解控制][主体内容][主体右边显示贺角控制][/主体]
[底部][底部圆解显示控制][/底部]
得到今天的测试代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>CSS圆角框加组件开发--测试过程</title>
<style type="text/css">
<!--
#box,#topbox,#bottombox{
width:400px;
}
#box .content{ background-color:#FFCC00;height:400px;}
<?php
for($y=1;$y<=4;$y++){
$x=(int)sqrt(4*4-$y*$y);
$sx=4-$x;
echo ".line{$y}{height:1px;overflow:hidden; background-color:#FFCC00;margin: 0 {$sx}px;}\n";
}
?>
-->
</style>
</head>
<body>
<div id="topbox">
<?php
for($y=4;$y>=1;$y--){
echo "<div class=\"line{$y}\"></div>\n";
}
?>
</div>
<div id="box">
<div class="content"> aaaaaaaaaaaaaaaaaa</div>
</div>
<div id="bottombox">
<?php
for($y=1;$y<=4;$y++){
echo "<div class=\"line{$y}\"></div>\n";
}
?>
</div>
</body>
</html>