svg,vml 画圆

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head><title>javascript画圆</title></head>
<body>
<div id="svg" style="width:200px;height:200px;"> </div>
<script type="text/javascript">
var cont;
var circle=new Function();
if (document.createElementNS) {
    svgNS = "http://www.w3.org/2000/svg";
    svg = document.createElementNS(svgNS, "svg");
    SVG = (svg.x != null);

    createSVGVML = function(o, antialias) {
        cont = document.createElementNS(svgNS, "svg");
        o.appendChild(cont);
        svgAntialias = antialias;
       
    }

    circle = function(diam, color) {
        var o = document.createElementNS(svgNS, "circle");
       
        o.setAttribute("shape-rendering", false);
        o.setAttribute("stroke-width", "2px");
        o.setAttribute("stroke-color", color);
        o.setAttribute("r", Math.round(diam / 2));
       
        o.setAttribute("cx", (diam / 2+2)+"px");
        o.setAttribute("cy", (diam / 2+2)+"px");
        o.setAttribute("stroke", color);
        o.setAttribute("fill", "none");
        o.style.cursor = "pointer";
        cont.appendChild(o);
    }
}
else if(document.createStyleSheet){
    createSVGVML = function(o, antialias) {
        document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
        var style = document.createStyleSheet();
        style.addRule('v//:*', "behavior: url(#default#VML);");
        style.addRule('v//:*', "antialias: "+antialias+";");
        cont = o;
    }
    circle = function (diam, filled) {
        var o = document.createElement("v:oval");
        o.style.position = "absolute";
        o.style.cursor = "pointer";
        o.strokeweight = 2;
        o.filled = filled;
        o.style.width = diam + "px";
        o.style.height = diam + "px";

        cont.appendChild(o);
        try{
            return o;
        }finally{
            o=null;
        }
    }

}
createSVGVML(document.getElementById("svg"));

circle(100,"#cccccc");

</script>
</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值