简体   繁体   English

如何在javascript代码中实现html元素?

[英]How to implement a html element inside a javascript code?

I am trying to design a sample web page, and I'm facing some issues with svg.... 我正在尝试设计一个示例网页,我正面临一些svg的问题....

I have created an svg circle with a line over it which will rotate with in the circle. 我创建了一个svg圆圈,在它上面有一条线,它将在圆圈中旋转。 Here is the sample code. 这是示例代码。

<?xml version="1.0" encoding="iso-8859-1"?>

<svg width="100%" height="100%">
<circle cx="200" cy="200" r="100" stroke="black" stroke-width="4" fill="black" />
<g transform="translate(200,200)">
<line x1="0" y1="0" x2="100" y2="0" style="stroke:rgb(255,255,255);stroke-width:2">
<animateTransform attributeName="transform"
                        attributeType="XML"
                        type="rotate"
                        from="25" to="360" dur="100s"/>
</line>
</svg>

In the sample code above the 'line' will start rotating immediately when the page is launched, but I want the line to be rotated after I press the START button, something like this... 在上面的示例代码中,'line'将在页面启动时立即开始旋转,但我希望在按下START按钮后旋转线,这样的话......

<input type="button" value=" START " onclick="start()" class="control-menu-top-btn" id="green-btn">

<script language="javascript" type="text/javascript">
function start()
{
  .. ?
}
</script>

The beginElement method will start an animation. beginElement方法将启动动画。 Setting the begin attribute to indefinite in the markup will stop it from running before the javascript starts it. 在标记中将begin属性设置为indefinite将使其在javascript启动之前停止运行。

 html, body { width: 100%; height: 100%; } 
 <input type="button" value=" START " onclick="start()" class="control-menu-top-btn" id="green-btn"> <script> function start() { document.getElementById("transform").beginElement(); } </script> <svg width="100%" height="100%"> <circle cx="200" cy="200" r="100" stroke="black" stroke-width="4" fill="black" /> <g transform="translate(200,200)"> <line x1="0" y1="0" x2="100" y2="0" style="stroke:rgb(255,255,255);stroke-width:2"> <animateTransform id="transform" attributeName="transform" attributeType="XML" type="rotate" from="25" to="360" dur="100s" begin="indefinite" /> </line> </g> </svg> 

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

相关问题 如何使用 HTML/JavaScript 实现自定义代码编辑器? - How to implement custom code editor with HTML/JavaScript? 如何通过JavaScript和HTML中的坐标搜索元素内部 - How to search inside an element by coordinates in javascript and HTML 如何使用JavaScript将元素添加到HTML5代码中 - How to add a element to HTML5 code with JavaScript 如果 html 内联元素内部有块元素,如何使用 javascript 拆分它 - how to split an html inline element if it has block element inside with javascript 如何在JavaScript和HTML中实现Squeeze Box示例代码? - How to implement Squeeze Box sample code in JavaScript and HTML? 如何直接在 JavaScript 代码中实现 onclick 功能而不是 html 标签? - How to implement onclick function directly in JavaScript code instead of html tag? 如何测试引用html文件中html元素的JavaScript代码 - How to test JavaScript code that references a html element in a html file html如何识别一段javascript代码中的html标签? - How does html recognize the html tags inside a piece of javascript code? 在javascript中的另一个元素中获取html元素 - get html element inside another element in javascript 如何在HTML的head元素内有条件地呈现CSS和JavaScript - How to conditionally render CSS and JavaScript inside head element of an HTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM