码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-05-09 18:59:47      阅读:421      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   ext   

矢量标记语言 --- Vector Markup Language

运行它的代码需要打开IE的兼容性视图

如有疑问请参考:http://msdn.microsoft.com/en-us/library/bb264280(VS.85).aspx

bubuko.com,布布扣

代码如下:

bubuko.com,布布扣
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
    <!-- VML requires VML namespace and behavior. -->
    <style>
        v\:* { behavior: url(#default#VML); }
    </style>
    <script type="text/javascript">
        // Your JavaScript code will go here.

        //Flag to stop rectangle from spinning.
        var spin;
        //Flag to first call makeRect function
        var first = true;
        // Make rectangle.
        function makeRect() {
            //if not first call, return.
            if(first == false)
                return;
            first = false;

            // Create element in memory.
            var r = document.createElement("v:rect");

            // Define width, height, color, and unique ID.
            r.style.width = 100;
            r.style.height = 100;
            r.fillcolor = "purple";
            r.id = "myRect";

            // Attach rectangle to the document at the the specified Div.
            var anchorDiv = document.getElementById(‘anchorDiv‘);
            anchorDiv.appendChild(r);
        }

        // Set up the rotation.
        function rotateRect() {
            // Call spinRect function every 10 milliseconds.
            // The spin variable allows us to clear the call to setInterval.
            spin = setInterval("spinRect()", 10);
        }

        // Spin the rectangle by specified increment every time function called.
        function spinRect() {
            // Increment rectangle rotation by 1 degrees.
            var myRect = document.getElementById(‘myRect‘);
            myRect.rotation += 1;
        }
    </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. -->
<input type="BUTTON" value="Stop!" onclick="clearInterval(spin)">
<br><br>
<!-- Node where new rectangle will be attached. -->
<div id="anchorDiv" style="border: dotted"></div>

</body>
</html>
bubuko.com,布布扣

 

 

bubuko.com,布布扣

 

运行结果如下:

 

bubuko.com,布布扣

 

bubuko.com,布布扣

 

 

 

html --- VML --- javascript --- 旋转矩形,布布扣,bubuko.com

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

标签:style   blog   class   code   java   ext   

原文地址:http://www.cnblogs.com/kodoyang/p/Html_VML_RotateRectangle_Javascript.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!