Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 874|回复: 0

CSS Don't

[复制链接]

该用户从未签到

发表于 2011-7-29 21:28:04 | 显示全部楼层 |阅读模式
本节列出了在使用 css 时尽量避免使用的技术。



Internet Explorer Behaviors

它是什么?Internet Explorer 5 引入了行为 (behaviors)。behaviors 是一种通过使用 css 向 HTML 元素添加行为的方法。

为什么要避免它?只有 Internet Explorer 支持 behavior 属性。

用什么代替?请使用 javaScript 和 html DOM 取而代之。



例子 1 - Mouseover Highlight

下面的 html 文件中有一个 <style> 元素,它为 <h1> 元素定义了一个行为:
[pre]<html>
<head>
<style type="text/css">
h1 { behavior: url(behave.htc) }
</style>
</head>

<body>
<h1>Mouse over me!!!</h1>
</body>
</html>[/pre]
下面是 XML 文档 "behave.htc":
[pre]<attach for="element" event="onmouseover" handler="hig_lite" />
<attach for="element" event="onmouseout" handler="low_lite" />

<script type="text/javascript">
function hig_lite()
{
element.style.color='red';
}

function low_lite()
{
element.style.color='blue';
}
</script>[/pre]
behavior 文件包含了针对元素的 javaScript 和 事件句柄。

假如您使用 Internet Explorer,可以切身试一下(把鼠标放在例子中的文本上)。



例子 2 - Typewriter Simulation

下面的 html 文件中有一个 <style> 元素,它为 id 为 "typing" 的元素定义了一个行为:
[pre]<html>
<head>
<style type="text/css">
#typing
{
behavior:url(behave_typing.htc);
font-family:'courier new';
}
</style>
</head>

<body>
<span id="typing" speed="100">IE5 introduced Dhtml behaviors.
Behaviors are a way to add Dhtml functionality to html elements
with the ease of css.<br /><br />How do behaviors work?<br />
By using XML we can link behaviors to any element in a web page
and manipulate that element.</p>
</span>
</body>
</html>[/pre]
下面是 XML 文档 "behave.htc":
[pre]<attach for="window" event="onload" handler="beginTyping" />
<method name="type" />

<script type="text/javascript">
var i,text1,text2,textLength,t;

function beginTyping()
{
i=0;
text1=element.innerText;
textLength=text1.length;
element.innerText="";
text2="";
t=window.setInterval(element.id+".type()",speed);
}

function type()
{
text2=text2+text1.substring(i,i+1);
element.innerText=text2;
i=i+1;
if (i==textLength)
  {
  clearInterval(t);
  }
}
</script>[/pre]
假如您使用 Internet Explorer,可以切身试一下。

<html>
<head>
<style type="text/css">
#typing
{
behavior:url("/example/csse/behave_typing.htc");
font-family:'courier new';
}
</style>
</head>

<body>
<span id="typing" speed="100">IE5 introduced Dhtml behaviors. Behaviors are a way to add Dhtml functionality to html elements with the ease of css.<br /><br />
How does behaviors work?<br />By using XML we can link behaviors to any element in a web page and manipulate that element.</p>
</span>
</body>
</html>
回复

使用道具 举报

  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2011-7-29 21:37:01 | 显示全部楼层
    谢谢楼主分享。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-13 00:10 , Processed in 0.352539 second(s), 45 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表