湮灭的风流-基于JavaScript的CSS技术概览
自从CSS出现以来,就有厂商希望CSS能够更加灵活一点,最早的CSS动态化体现为“动态表达式”(或动态属性,Dynamic attribute)的构想,动态表达式的构想也许是源自于以下的一些场景:
- 元素的尺寸或者位置由浏览器或者html文档来计算
- 使用变量作为style属性的值,比如频繁使用的颜色,用一个全局变量
包括浏览器的鼻祖Netscape以及IE浏览器都试图在CSS中使用javascript,Netscape公司在很久很久以前提出了JSS技术,当然只支持Netscape浏览器:
“JavaScript Style Sheets. In the beginning, they were JASS (JavaScript Accessible Style Sheets), then JSSS or JSS (JavaScript Style Sheets), and now Netscape has taken to calling them Style Sheets with JavaScript Syntax. They exist in the Netscape DHTML documentation, a few books, and a couple of old third party articles on the web. The best introduction to JSS is by HTML veteran Chuck Musciano, at SunWorld. A concise, clear examination, this article was written a year ago (April 1997). Next to nothing has been written on the Web since then。”
一段经典的Netscape浏览器的JSS代码如下所示:
with (parent.frames.main.document.classes.items.SPAN) {
width = menuWidth;
color = fntCol;
fontSize = fntSiz;
fontWeight = fntWgh;
fontStyle = fntSty;
fontFamily = fntFam;
borderWidth = borWid;
borderColor = borCol;
borderStyle = borSty;
lineHeight = linHgt;
}
</STYLE>
{
position: absolute;
width: 100px;
height: 100px;
left: expression(document.body.offsetWidth - 110 + "px");
top: expression(document.body.offsetHeight - 110 + "px");
background: red;
}
- 1、CSS本身的静态特性
- 2、W3C标准与浏览器版本不能也永远不能同步的矛盾
- 3、html开发人员的期望与W3C标准不能也永远不能同步的矛盾
html的CSS技术本身的缺点已经引起了软件开发巨头的注意,在当前狂躁的应用程序标记语言中,比如微软的XAML或adobe的MXML,其CSS(暂且称之为CSS吧)不仅可以动态定义,甚至还可以定义属性、内容和事件。也许,在几年之后,我们将看到W3C准备修正新的CSS标准,让其更加动态化。