简体   繁体   English

svg画布里面的原生按钮标签

[英]native button tag inside svg canvas

I need to place a button tag inside a SVG canvas, is there a way? 我需要在SVG画布中放置一个按钮标签,有没有办法? (I'm using raphael JS) (我正在使用raphael JS)

I know I can 'draw' a button inside the svg canvas and code the onclick event but I want to preserve the native look and feel of the browser buttons. 我知道我可以在svg画布内“绘制”一个按钮并对onclick事件进行编码,但我希望保留浏览器按钮的原生外观。 Thank you. 谢谢。

It is possible to use HTML buttons within SVG, using the SVG foreignObject element: http://www.w3.org/TR/SVG/extend.html#ForeignObjectElement 可以使用SVG foreignObject元素在SVG中使用HTML按钮: http//www.w3.org/TR/SVG/extend.html#ForeignObjectElement

There is an example included in the spec of how to use it. 有关如何使用它的规范中包含一个示例。

Unfortunately, I'm not sure how you could best use foreignObject from raphaeljs. 不幸的是,我不确定如何最好地使用来自raphaeljs的foreignObject。 I believe that foreignObject is not exposed as part of the RapahelJS API. 我相信foreignObject不会作为RapahelJS API的一部分公开。 The reason for this is that there may not be a clean way of achieve the same goal with VML on IE. 原因是在IE上可能没有一种干净的方法来实现与VML相同的目标。 However, raphaeljs does make it fairly easy to access the underlying native SVG DOM nodes of its objects, so if IE compatibility is not essential for your application, then it should be fairly easy to use foreignObject using the regular SVG DOM API. 但是,raphaeljs确实可以很容易地访问其对象的底层本机SVG DOM节点,因此如果IE兼容性对于您的应用程序不是必不可少的,那么使用常规SVG DOM API使用foreignObject应该相当容易。 For example, you could do the following: 例如,您可以执行以下操作:

var paper = Raphael("canvas", 640, 480);
var svgRoot = paper.canvas; //everywhere except IE, this is an SVGSVGElement
var fo = document.createElementNS(paper.svgns,"foreignObject")
svgRoot.appendChild(fo);
//then add your HTML DOM nodes to fo here using regular HTML DOM...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM