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

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

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

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

代码如下:

<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>

 

 

 

运行结果如下:

 

 

 

 

 

html --- VML --- javascript --- 旋转矩形,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。