?? 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 的緊密結(jié)合,使的給 VML 增加事件變得很容易.所有的 HTML 里面的事件都可以應(yīng)用到 VML 中間來!下面的例子是演示:當(dāng)鼠標(biāo)移動到圓的時候,圓就跟著鼠標(biāo)移動了,當(dāng)鼠標(biāo)點擊后,圓停止移動。<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的事件區(qū)域是嚴(yán)格按照本身的形狀的,并不是像圖片那樣,都是矩形。順便介紹一下 Function 對象,使用Function 對象,如果函數(shù)的內(nèi)容比較少,而且調(diào)用就一次,就可以使用
Function 對象了,使用方法就是用 new 創(chuàng)建一個 Function 對象,參數(shù)就是 函數(shù)的內(nèi)容。控制事件的比較好的辦法是使用一個全局變量,一個事件的執(zhí)行依賴一個全局變量,而另一個事件可以設(shè)置這個全局變量,
這樣一來,就可以讓事件來控制事件了。
</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>
上一節(jié):<a href="step22.html">放大縮小VML</a><br>
下一節(jié):<a href="step31.html">數(shù)據(jù)圖表</a>
</td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -