📄 step23.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title>Thinking in VML</title>
</head>
<STYLE>
v\:* { BEHAVIOR: url(#default#VML) }
</STYLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="style.css" />
<script language="JScript">
var canmove=false;
function move()
{
circle.style.position="absolute";
canmove=true;
document.onmousemove=new Function("if(canmove){circle.style.posLeft=event.x;circle.style.posTop=event.y;}");
}
document.onclick=new Function("canmove=false");
</script>
<body>
<table align="center">
<tr>
<td align="center" class="title"><strong>给VML增加事件</strong></td>
</tr>
<tr>
<td >
<div class="memo" style="width:700;line-height:23px">
VML 和 HTML 的紧密结合,使的给 VML 增加事件变得很容易.所有的 HTML 里面的事件都可以应用到 VML 中间来!下面的例子是演示:当鼠标移动到圆的时候,圆就跟着鼠标移动了,当鼠标点击后,圆停止移动。<br><br>
<div class="memo">
<v:oval id="circle" style="position:relative;width:100;height:80;" <font color=red>onmouseover="move()"</font> fillcolor=red /><br>
<script><br>
var canmove=false;<br>
function move()<br>
{<br>
circle.style.position="absolute";<br>
canmove=true;<br>
document.onmousemove=new Function("<font color=red>if(canmove){circle.style.posLeft=event.x;circle.style.posTop=event.y;}</font>");<br>
}<br>
document.onclick=new Function("canmove=false");<br>
</script><br>
</div><br>
<v:oval id="circle" style="position:relative;width:100;height:80;" onmouseover="move()" fillcolor=red /><br><br>
不知道你有没有注意,VML的事件区域是严格按照本身的形状的,并不是像图片那样,都是矩形。顺便介绍一下 Function 对象,使用Function 对象,如果函数的内容比较少,而且调用就一次,就可以使用
Function 对象了,使用方法就是用 new 创建一个 Function 对象,参数就是 函数的内容。控制事件的比较好的办法是使用一个全局变量,一个事件的执行依赖一个全局变量,而另一个事件可以设置这个全局变量,
这样一来,就可以让事件来控制事件了。
</div>
</td>
</tr>
<tr>
<td class="title">
<p align="right"><a href="javascript:self.scrollTo(0,0)">Top</a></p>
<a href="index.html">返回目录</a><br>
上一节:<a href="step22.html">放大缩小VML</a><br>
下一节:<a href="step31.html">数据图表</a>
</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -