CSS ×¢ÒâÊÂÏî
±¾½ÚÁгöÁËÔÚʹÓà CSS ʱ¾¡Á¿±ÜÃâʹÓõļ¼Êõ¡£
Internet Explorer Behaviors
ËüÊÇʲô£¿Internet Explorer 5 ÒýÈëÁËÐÐΪ (behaviors)¡£behaviors ÊÇÒ»ÖÖͨ¹ýʹÓà CSS Ïò HTML ÔªËØÌí¼ÓÐÐΪµÄ·½·¨¡£
ΪʲôҪ±ÜÃâËü£¿Ö»ÓÐ Internet Explorer Ö§³Ö behavior ÊôÐÔ¡£
ÓÃʲô´úÌæ£¿ÇëʹÓà JavaScript ºÍ HTML DOM È¡¶ø´úÖ®¡£
Àý×Ó 1 - Mouseover Highlight
ÏÂÃæµÄ HTML ÎļþÖÐÓÐÒ»¸ö <style> ÔªËØ£¬ËüΪ <h1> ÔªËØ¶¨ÒåÁËÒ»¸öÐÐΪ£º
<html>
<head>
<style type="text/css">
h1 { behavior: url(behave.htc) }
</style>
</head>
<body>
<h1>Mouse over me!!!</h1>
</body>
</html>
ÏÂÃæÊÇ XML Îĵµ "behave.htc"£º
<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>
behavior Îļþ°üº¬ÁËÕë¶ÔÔªËØµÄ JavaScript ºÍ ʼþ¾ä±ú¡£
Èç¹ûÄúʹÓà Internet Explorer£¬¿ÉÒÔÇ××ÔÊÔһϣ¨°ÑÊó±ê·ÅÔÚÀý×ÓÖеÄÎı¾ÉÏ£©¡£
Àý×Ó 2 - Typewriter Simulation
ÏÂÃæµÄ HTML ÎļþÖÐÓÐÒ»¸ö <style> ÔªËØ£¬ËüΪ id Ϊ "typing" µÄÔªËØ¶¨ÒåÁËÒ»¸öÐÐΪ£º
<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>
ÏÂÃæÊÇ XML Îĵµ "behave.htc"£º
<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>
Èç¹ûÄúʹÓà Internet Explorer£¬¿ÉÒÔÇ××ÔÊÔһϡ£