The close integration of VML and HTML makes it easy to add events to VML. All events in HTML can be applied to VML! The following example is a demonstration: when the mouse moves to the circle, the circle moves with the mouse. When the mouse is clicked, the circle stops moving.
onmouseover="move()" fillcolor=red />
<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>
I don’t know if you have noticed, The event area of VML strictly follows its own shape, not all rectangles like the picture. By the way, let me introduce the Function object. Use the Function object. If the content of the function is relatively small and it is called only once, you can use the Function object. The method of use is to use new to create a Function object, and the parameters are the contents of the function. A better way to control events is to use a global variable. The execution of an event depends on a global variable, and another event can set this global variable. In this way, the event can be controlled by the event.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn