以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  在asp/html页面中如何获取SVG上事件的坐标  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=19627)


--  作者:wulemale
--  发布时间:6/14/2005 9:06:00 PM

--  在asp/html页面中如何获取SVG上事件的坐标
页面中嵌入了SVG,如何在HTML中获取SVG中产生的事件的一些属性,如坐标等。

--  作者:犬神狼
--  发布时间:6/14/2005 10:14:00 PM

--  

<HTML>
<HEAD>
<TITLE>Changing Fill Color Example</TITLE>
<META NAME="author" CONTENT="Glen H. Gersten">
<!--
NOTICE:  ?[1999-2001] Adobe Systems Incorporated.  Adobe hereby grants you the rights to reproduce, modify and distribute this file and its contents, not including any fonts, audio files or raster images included or embedded in or linked to this file, (the "Software"), and to grant such rights to other parties subject to the following:  This notice shall be included in any copy of the Software or any portion thereof.  THE SOFTWARE IS PROVIDED TO YOU AS-IS, WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL ADOBE BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
-->

<SCRIPT>
// change the fill color of an element
function setFill() {
         // get the SVG Document element
         SVGDoc = document.colorSVG.getSVGDocument()

         // get the element we want to change
         var thisElem = SVGDoc.getElementById('colorRect')

         // get the style element
         var thisStyle = thisElem.getStyle()

         // get the color value from the form
         var thisColor = document.colorForm.colorChoice.value

         // perform the fill color change
         thisStyle.setProperty('fill', thisColor)
}

</SCRIPT>
</HEAD>

<BODY>
Enter a Hex Value (preceded by #) or Color Name

<FORM NAME="colorForm" onSubmit="setFill(); return false;">
<INPUT TYPE="text" NAME="colorChoice">
<INPUT TYPE="submit" VALUE="Submit Color">
</FORM>

<EMBED SRC="colorpicker.svgz" TYPE="image/svg+xml"
         NAME="colorSVG" HEIGHT="50" WIDTH="50"
         PLUGINSPAGE="http://www.adobe.com/svg/viewer/install/">

</BODY>
</HTML>


--  作者:wulemale
--  发布时间:6/15/2005 8:43:00 AM

--  
html中可以控制SVG的一些属性,我想知道的是如何获取事件发生点的坐标,例如我在svg上click一下,在html中能得到点击点的x、y坐标吗?
--  作者:犬神狼
--  发布时间:6/15/2005 10:47:00 AM

--  
在SVG图里点击,获得的坐标应该还是在SVG坐标系中的坐标吧,你是要把坐标转换成相对于HTML的还是就只要能获得点击处的坐标就够了?
function mouseClick1(event)
    {
       xCoord = event.getClientX();
       yCoord = event.getClientY();
}这两句就可以获得在SVG点击处的坐标值
--  作者:liujun808
--  发布时间:9/2/2005 11:16:00 AM

--  
 var XPos = evt.getClientX();
 var YPos = evt.getClientY();
--  作者:zhou_gong
--  发布时间:9/2/2005 12:52:00 PM

--  
var svgObj =document.getElementById("svgid") ,getSVGDocument(); //svgid是HTML的  <EMBED>中放入SVG文件的ID属性
var svgRoot =svgDoc.DocumentElement(); //svg DOM的根的元素
svgRoot.AddLis????("mousermove",userFunction,false);//就是增加一个事件监听的意思,函数名忘了,自己查一上文档吧

userFunction(evt)
{
//你的代码

//evt.clientX,evt.clientY是你需要的坐标了
}


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms