可缩放矢量图形英语Scalable Vector GraphicsSVG)是基于可扩展标记语言(XML),

  用于描述二维矢量图形的一种图形格式。SVG由W3C制定,是一个开放标准

在 Internet Explorer 10(Quirks 和 IE10 文档模式)中,矢量标记语言 (VML) 已过时。

  如有疑问请参考:http://msdn.microsoft.com/zh-cn/library/ie/hh801223

  更多疑问请参考:http://zh.wikipedia.org/wiki/SVG

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>旋转矩形</title>
    <script>
        // Global variables.
        // Define SVG namespace.
        var svgNS = "http://www.w3.org/2000/svg";
        // Placeholder for parent SVG element to be created.
        var mySvg;
        // Placeholder for rectangle object to be created.
        var myRect;
        // Flag to stop rectangle spinning.
        var spin;
        // Initial angle to start rotation from.
        var myAngle = 0;
        // Values of center of rotation.
        var myX = 250;
        var myY = 150;

        // Make Rectangle.
        function makeRect() {

            if(document.getElementsByTagNameNS(svgNS, "svg").length != 0 )
                return;
            /*
             * createElementNS() 方法可创建带有指定命名空间的元素节点
             * setAttributeNS()  方法创建或改变具有命名空间的属性
             */
            // Create parent SVG element with width and height.
            mySvg = document.createElementNS(svgNS,"svg");
            mySvg.setAttributeNS(null,"width", "800px");
            mySvg.setAttributeNS(null,"height", "450px");

            // Create rectangle element from SVG namespace.
            myRect = document.createElementNS(svgNS,"rect");
            // Set rectangle's attributes.
            myRect.setAttributeNS(null,"width","145px");
            myRect.setAttributeNS(null,"height","90px");
            myRect.setAttributeNS(null,"x","200px");
            myRect.setAttributeNS(null,"y","100px");
            myRect.setAttributeNS(null,"fill","lightcoral");
            myRect.setAttributeNS(null,"stroke","deepskyblue");
            myRect.setAttributeNS(null,"stroke-width","5px");

            // Append rectangle to the parent SVG element.
            // Append parent SVG element to the div node.
            mySvg.appendChild(myRect);
            document.getElementById("myAnchor").appendChild(mySvg);
        }

        // Do the rotation every 10 milliseconds until cancelled.
        function rotateRect() {
            spin = setInterval("spinRect()", 10);
        }
        // Spin rectangle by 5 degrees.
        function spinRect() {
            // Rotation is a subset of the transform attribute.
            // Note the use of quotes and plus signs with variables in SVG attribute call.
            myRect.setAttributeNS(null,"transform","rotate(" + myAngle + "," + myX + "," + myY + ")");
            myAngle += 5;
        }
    </script>
</head>
<body>

<br><br>

<!-- Button to create rectangle. -->
<input type="BUTTON" value="Make Rectangle" onclick="makeRect()">

<!-- Button to rotate rectangle. -->
<input type="BUTTON" value="Rotate Rectangle" onclick="rotateRect()">

<!-- Button to close webpage with spin variable. -->
<!-- clearInterval() 方法可取消由 setInterval() 设置的 timeout。
     clearInterval() 方法的参数必须是由 setInterval() 返回的 ID 值。-->
<input type="BUTTON" value="Stop!" onclick="clearInterval(spin)">

<br><br>

<!-- The rectangle will be attached to the document here. -->
<div id="myAnchor"></div>

</body>
</html>

运行结果如下:

html --- SVG --- javascript --- 旋转矩形的更多相关文章

  1. html --- VML --- javascript --- 旋转矩形

    矢量标记语言 --- Vector Markup Language 运行它的代码需要打开IE的兼容性视图 如有疑问请参考:http://msdn.microsoft.com/en-us/library ...

  2. cocos2d 判断旋转矩形是否包含某个点

    本来想画个图演示一下,但是折腾了一会发现画不好,我的win10系统没有安装office,以后再看的话再补上吧.不废话了. 如图所以,如果判断点P是否被矩形A所包含,非常容易.那么如果矩形A以中心点逆时 ...

  3. css3+javascript旋转的3d盒子

    今天写点css3,3d属性写的3d盒子,结合javascript让盒子随鼠标旋转起来 今天带了css3新属性3d <!DOCTYPE html> <html> <head ...

  4. 旋转矩形碰撞检测 OBB方向包围盒算法

    在cocos2dx中进行矩形的碰撞检测时需要对旋转过的矩形做碰撞检查,由于游戏没有使用Box2D等物理引擎,所以采用了OBB(Oriented bounding box)方向包围盒算法,这个算法是基于 ...

  5. RotateRect(旋转矩形)的倾斜旋转变换矫正

    在Opencv中的图像处理中,经常要用到minAreaRect()函数求最小外接矩形,该函数的返回值就是一个RotatedRect类对象. RotatedRect类定义如下: class CV_EXP ...

  6. javascript中矩形的碰撞检测---- 计算碰撞部分的面积

    今天在做一个拖拽改变元素排序的东西的时候,在做被拖动元素同时碰撞到两个元素时,究竟应该与哪个元素交换位置的问题上,纠结到崩溃,实在是想不到别的办法去做了,只能去想办法计算碰撞的面积. 这应该不是最合适 ...

  7. opencv HSV找颜色,找轮廓用最小旋转矩形框出

    #include <opencv2/opencv.hpp> #include<iostream> #include<string> using namespace ...

  8. SVG基础以及使用Javascript DOM操作SVG

    SVG 不依赖分辨率 支持事件处理器 最适合带有大型渲染区域的应用程序(比如谷歌地图) 复杂度高会减慢渲染速度(任何过度使用 DOM 的应用都不快) 不适合游戏应用 Canvas 依赖分辨率 不支持事 ...

  9. 矩形旋转碰撞,OBB方向包围盒算法实现

    怎样进行2D旋转矩形的碰撞检測.能够使用一种叫OBB的检測算法(Oriented bounding box)方向包围盒.这个算法是基于SAT(Separating Axis Theorem)分离轴定律 ...

随机推荐

  1. 278. First Bad Version

    题目: You are a product manager and currently leading a team to develop a new product. Unfortunately, ...

  2. Java:进制转换

    进制转换是常常需要的一种数据处理,在java中的一些类中封装了具有转换功能的方法,这个不做介绍.其实,进制之间的转化是通过先位异或&,再位移动>>>的方式实现的. 例如,对于 ...

  3. JBoss7配置指南

    JBoss7配置指南   1.    jboss各主要版本特性... 3 1.1.     jboss4特性... 3 1.2.     jboss5特性... 5 1.3.     jboss6特性 ...

  4. docker基本概念,创建、起动实例,保存自定义镜像等常用操作

    14年docker火了一阵,当时自学整理了一份文档,后来冷落了. 现在发现很多同事还是想学习docker,但无从下手,所以重新整理了这篇分享,10分钟就可以带你彻底理解docker,并能够创建属于自己 ...

  5. 动态库加载出错,cannot restore segment prot after reloc: Permission denied

    转自:taolinke的博客 项目中碰到的问题,编译好的so文件,放到其他机器上去加载,报了错误,cannot restore segment prot after reloc: Permission ...

  6. 谈谈防止Ajax重复点击提交

    首先说说防止重复点击提交是什么意思. 我们在访问有的网站,输入表单完成以后,单击提交按钮进行提交以后,提交按钮就会变为灰色,用户不能再单击第二次,直到重新加载页面或者跳转.这样,可以一定程度上防止用户 ...

  7. YTU 2605: 熟悉题型——自由设计(比较大小-类模板)

    2605: 熟悉题型--自由设计(比较大小-类模板) 时间限制: 1 Sec  内存限制: 128 MB 提交: 125  解决: 107 题目描述 声明一个类模板,利用它分别实现两个整数.浮点数和字 ...

  8. TFSAPI

    Team Foundation Server (TFS)工具的亮点之一是管理日常工作项, 工作项如Bug, Task,Task Case等. 使用TFS API编程访问TFS服务器中的工作项, 步骤如 ...

  9. linux/shell 文本文件删除/删掉空行

    分别用sed awk perl grep 实现: sed '/^$/d' input.txt > output.txt #output file: output.txt sed -i '/^$/ ...

  10. Java 日期 Api

    public class TimeTest { public static void main(String[] args) { Date d1 = new Date(); SimpleDateFor ...