下面是我做的一个小例子:
font_effect.htc
复制代码 代码如下:
////////////////////////“行为”文档开始////////////////////////////
//给“行为”增加四个鼠标事件
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="glowit()"/>
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="noglow()"/>
<PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="font2yellow()"/>
<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="font2blue()"/>
//给“行为”定义二个方法,注意NAME的值里不能加括号
<PUBLIC:METHOD NAME="move_down"/>
<PUBLIC:METHOD NAME="move_right"/>
<script language ="JScript">
//定义一个保存字体颜色的变量
var font_color;
//定义向下移动文字的方法
function move_down()
{
element.style.posTop += 10;
}
//定义向右移动文字的方法
function move_right()
{
element.style.posLeft += 10;
}
//定义鼠标onmouseup事件的调用函数
function font2blue()
{
if (event.srcElement == element)
{
element.style.color = "blue";
}
}
//定义鼠标onmousedown事件的调用函数
function font2yellow()
{
if (event.srcElement == element)
{
element.style.color = "yellow";
}
}
//定义鼠标onmouseover事件的调用函数
function glowit()
{
if (event.srcElement == element)
{
font_color=style.color;
element.style.color = "white";
element.style.filter = "glow(color=red, strength=2)";
}
}
//定义鼠标onmouseout事件的调用函数
function noglow()
{
if (event.srcElement == element)
{
element.style.filter = "";
element.style.color = font_color;
}
}
</script>
//////////////////“行为”文档结束///////////////////////////////
htcExample.htm
复制代码 代码如下:
<html>
<head>
<title>行为效果演示</title>
<style>
.myfilter{behavior:url(font_effect.htc);position:relative;width:880}
</style>
</head>
<body>
<button onclick="myspan.move_right();">向右移动文字</button>
<button onclick="myspan.move_down();">向下移动文字</button>
<br /><br />
<span id="myspan" class='myfilter'>鼠标指向后产生辉光,同时文字变白;按下鼠标后文字变黄;抬起鼠标后文字变蓝;鼠标离开后文字恢复原状</span>
</body>
</html>
发表评论