svg鼠标响应事件的四种方法(其中两种可支持火狐)
2009-10-10 09:28
423 查看
svg鼠标响应事件的四种方法
Mouse Events - SMIL
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="5" y="5" width="40" height="40" fill="red">
<set attributeName="fill" to="blue" begin="click"/>
</rect>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/svg_smil/click.svg
Mouse Events - Attributes
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ATTLIST svg
xmlns:a3 CDATA #IMPLIED
a3:scriptImplementation CDATA #IMPLIED>
<!ATTLIST script
a3:scriptImplementation CDATA #IMPLIED>
]>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
function changeColor(evt) {
var rect = evt.target;
rect.setAttributeNS(null, "fill", "purple")
}
]]></script>
<rect x="5" y="5" width="40" height="40" fill="red"
onclick="changeColor(evt)"/>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/svg_js/onclick.svg
Mouse Events - JavaScript+SMIL
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ATTLIST svg
xmlns:a3 CDATA #IMPLIED
a3:scriptImplementation CDATA #IMPLIED>
<!ATTLIST script
a3:scriptImplementation CDATA #IMPLIED>
]>
<svg onload="makeShape(evt)"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
var svgns = "http://www.w3.org/2000/svg";
function makeShape(evt) {
if ( window.svgDocument == null )
svgDocument = evt.target.ownerDocument;
var rect = svgDocument.createElementNS(svgns, "rect");
rect.setAttributeNS(null, "x", "5");
rect.setAttributeNS(null, "y", "5");
rect.setAttributeNS(null, "width", "40");
rect.setAttributeNS(null, "height", "40");
rect.setAttributeNS(null, "fill", "green");
var set = svgDocument.createElementNS(svgns, "set");
set.setAttributeNS(null, "attributeName", "fill");
set.setAttributeNS(null, "to", "blue");
set.setAttributeNS(null, "begin", "click");
rect.appendChild(set);
svgDocument.documentElement.appendChild(rect);
}
]]></script>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/js_dom_smil/click_js_smil.svg
Mouse Events - EventListener
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ATTLIST svg
xmlns:a3 CDATA #IMPLIED
a3:scriptImplementation CDATA #IMPLIED>
<!ATTLIST script
a3:scriptImplementation CDATA #IMPLIED>
]>
<svg onload="makeShape(evt)"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
var svgns = "http://www.w3.org/2000/svg";
function makeShape(evt) {
if ( window.svgDocument == null )
svgDocument = evt.target.ownerDocument;
var rect = svgDocument.createElementNS(svgns, "rect");
rect.setAttributeNS(null, "x", 5);
rect.setAttributeNS(null, "y", 5);
rect.setAttributeNS(null, "width", 40);
rect.setAttributeNS(null, "height", 40);
rect.setAttributeNS(null, "fill", "green");
rect.addEventListener("click", changeColor, false);
svgDocument.documentElement.appendChild(rect);
}
function changeColor(evt) {
var target = evt.target;
target.setAttributeNS(null, "fill", "purple");
}
]]></script>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/js_dom/click_js.svg
鼠标响应事件的四种方法,以click事件为例。 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="5" y="5" width="40" height="40" fill="red">
<set attributeName="fill" to="blue" begin="click"/>
</rect>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/svg_smil/click.svg
Mouse Events - Attributes
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ATTLIST svg
xmlns:a3 CDATA #IMPLIED
a3:scriptImplementation CDATA #IMPLIED>
<!ATTLIST script
a3:scriptImplementation CDATA #IMPLIED>
]>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
function changeColor(evt) {
var rect = evt.target;
rect.setAttributeNS(null, "fill", "purple")
}
]]></script>
<rect x="5" y="5" width="40" height="40" fill="red"
onclick="changeColor(evt)"/>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/svg_js/onclick.svg
Mouse Events - JavaScript+SMIL
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ATTLIST svg
xmlns:a3 CDATA #IMPLIED
a3:scriptImplementation CDATA #IMPLIED>
<!ATTLIST script
a3:scriptImplementation CDATA #IMPLIED>
]>
<svg onload="makeShape(evt)"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
var svgns = "http://www.w3.org/2000/svg";
function makeShape(evt) {
if ( window.svgDocument == null )
svgDocument = evt.target.ownerDocument;
var rect = svgDocument.createElementNS(svgns, "rect");
rect.setAttributeNS(null, "x", "5");
rect.setAttributeNS(null, "y", "5");
rect.setAttributeNS(null, "width", "40");
rect.setAttributeNS(null, "height", "40");
rect.setAttributeNS(null, "fill", "green");
var set = svgDocument.createElementNS(svgns, "set");
set.setAttributeNS(null, "attributeName", "fill");
set.setAttributeNS(null, "to", "blue");
set.setAttributeNS(null, "begin", "click");
rect.appendChild(set);
svgDocument.documentElement.appendChild(rect);
}
]]></script>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/js_dom_smil/click_js_smil.svg
Mouse Events - EventListener
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"
[
<!ATTLIST svg
xmlns:a3 CDATA #IMPLIED
a3:scriptImplementation CDATA #IMPLIED>
<!ATTLIST script
a3:scriptImplementation CDATA #IMPLIED>
]>
<svg onload="makeShape(evt)"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
a3:scriptImplementation="Adobe">
<script type="text/ecmascript" a3:scriptImplementation="Adobe"><![CDATA[
var svgns = "http://www.w3.org/2000/svg";
function makeShape(evt) {
if ( window.svgDocument == null )
svgDocument = evt.target.ownerDocument;
var rect = svgDocument.createElementNS(svgns, "rect");
rect.setAttributeNS(null, "x", 5);
rect.setAttributeNS(null, "y", 5);
rect.setAttributeNS(null, "width", 40);
rect.setAttributeNS(null, "height", 40);
rect.setAttributeNS(null, "fill", "green");
rect.addEventListener("click", changeColor, false);
svgDocument.documentElement.appendChild(rect);
}
function changeColor(evt) {
var target = evt.target;
target.setAttributeNS(null, "fill", "purple");
}
]]></script>
</svg>
实例演示:
http://www.kevlindev.com/tutorials/basics/events/mouse/js_dom/click_js.svg
相关文章推荐
- svg鼠标响应事件的四种方法(其中两种可支持火狐)
- svg鼠标响应事件的四种方法
- SVG鼠标事件响应的四种写法
- SVG鼠标事件响应的四种写法
- SVG鼠标事件响应的四种写法
- SVG鼠标事件响应的四种写法
- 在Activity中响应ListView内部按钮的点击事件的两种方法
- 在Activity中响应ListView内部按钮的点击事件的两种方法!!!
- 在Activity中响应ListView内部按钮的点击事件的两种方法
- 在Activity中响应ListView内部按钮的点击事件的两种方法
- FLASH中响应键盘事件的四种方法
- 模拟键盘鼠标事件有两种方法
- 如何避免鼠标移入子级触发父级的移出事件(两种方法)
- 3. android响应事件的四种方法(以onclick为例子)
- c++ builder里四种处理“鼠标离开窗体”事件的方法 转
- 在Activity中响应ListView内部按钮的点击事件的两种方法
- mouse添加鼠标移出移入事件 两种方法
- 页面响应事件跳转的两种方法
- 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件
- VC++ 中响应鼠标悬停事件的简单方法(2005-8-10)