`
scomouse
  • 浏览: 14960 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

vml

 
阅读更多

vml

The Vector Markup Language (矢量 可标记语言)的缩写.VML相当于IE里面的画笔,能实现你所想要的图形,而且结合脚本,可以让图形产生动态的效果。

一些文章介绍

http://www.itlearner.com/code/vml/step2.html

在需要创建vml的页面中 是需要一个命名空间的

<html xmlns:vml="urn:schemas-microsoft-com:vml" >


或者

document.namespaces.add('vml', 'urn:schemas-microsoft-com:vml', "#default#VML");

样式里面要加上

<style type="text/css">
vml/:* { behavior: url(#default#VML) }
</style>

ie8下有bug 我直接写在页面里面的vml始终出不来 杯具 所以只好创建元素的方式才创建了(听说ie6下的效果不错)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
.mark{
font-size : 12px;
margin : 0 auto;
display : block;
position : absolute;
text-align : right;
}
</style>
</head>
<body>
<script type="text/javascript" >
window.onload = function(){
document.createStyleSheet().addRule(".vml", "behavior:url(#default#VML);display:inline-block;");
if (!document.namespaces.vml && !+"/v1"){
document.namespaces.add("vml", "urn:schemas-microsoft-com:vml");
}

function $cVml(){
return document.createElement('<vml:shape class="vml">');
};

function attr(vml,config){
for(var i in config)
vml.setAttribute(i,config[i]);
}

function css(vml,config){
var str = "";
for(var i in config)
str += i == "opacity" ? ("filter:alpha(opacity="+ config[i] * 100+");"):(i+":"+config[i]+";");
vml.style.cssText = str;
}

var v = $cVml();
attr(v,{
StrokeWeight : 4,
StrokeColor : '#0000ff',
fillcolor : '#0000ff',
coordsize : '600,600',
path : 'm 0 0 l 10,10,20,20,30,30,40,40,50,50,60,60 e'
});
css(v,{
position : "absolute",
left : '0px',
top : '0px',
display : 'inline-block',
width : '600px',
height : '600px'
});
document.getElementById('ss').appendChild(v);
}

</script>
<div id='ss'><div>
</body>
</html>

m x,y:MoveTo把画笔移动到 (x,y);
l x,y:LineTo从当前点到(x,y)画一条线;可以给连续的几个点,VML会连续画出来直到遇到 x 命令。
x:Close结束一条线;
e:End结束画图
FillColor:填充颜色,使用HTML中规定的颜色;例如:fillcolor=red
Filled:是否要填充图形,如果图形不是封闭的,也会自动封闭图形进行填充。当Filled="true"(默认),fillcolor才有效果;
StrokeColor:线的颜色;
StrokeWeight:线的宽度;

CoordSize 表示吧vml划分成多少个点

如果吧vml的高宽设置成600px 600px

在设置CoordSize =‘600,600’ 这样vml中的1也就是1px了

CoordOrig 远点坐标 默认是0,0

一个简单的创建vml标签的对象

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
.mark{
font-size : 12px;
margin : 0 auto;
display : block;
position : absolute;
text-align : right;
}
</style>
</head>
<body>
<script type="text/javascript" >
window.onload = function(){
document.createStyleSheet().addRule(".vml", "behavior:url(#default#VML);display:inline-block;");
if (!document.namespaces.vml && !+"/v1"){
document.namespaces.add("vml", "urn:schemas-microsoft-com:vml");
}
var vml = {
container : null,
node : null,
init : function(container){
this.container = container;
this.width = container.offsetWidth;
this.height = container.offsetHeight;
return this;
},
$c : function(name){
name = name || 'shape';
this.node = document.createElement('<vml:'+name+' class="vml">');
return this;
},
attr : function(config){
for(var i in config)
this.node.setAttribute(i,config[i]);
return this;
},
css : function(config){
var str = "";
for(var i in config)
str += i == "opacity" ? ("filter:alpha(opacity="+ config[i] * 100+");"):(i+":"+config[i]+";");
this.node.style.cssText = str;
return this;
},
appendTo : function(p){
if(this.node!==null){
p?p.appendChild(this.node):this.container.appendChild(this.node);
}
return this;
}
}
vml.init(document.getElementById('ss')).$c().attr({
strokewidth : 1,
StrokeColor : '#0000ff',
filled : 't',
coordsize : '400,400',
path : 'm 0,0 l 15,0 15,15 30,15 30,30 45,30 45,45 60,45 60,60 e'
}).css({
position : "absolute",
left : '0px',
top : '0px',
display : 'inline-block',
width : '400px',
height : '400px'
}).appendTo();
}

</script>
<div id='ss' style="height:400px;width:400px; border:1px solid #030; margin:50px; position:relative"><div>
</body>
</html>

有几点要注意

1. 创建vml标签的时候 一定要用

document.createElement('<vml:'+name+' class="vml">');

这样形式 ie8下用document.createElement('vml');很可能会看不到

2.加了属性和样式后 在把vml添加到父元素上去 如果先加到父元素 在设置属性 也会看不到

3.父元素设置position:relative vml设置position:absolute 这样才能保证vml的坐标原点在父元素的左上角

不然会在浏览器的左上角

画饼图

path:画笔
path参数:
m x,y:MoveTo 把画笔移动到(x,y) ----就是画图的画笔起点
l x,y:LineTo 从M点到(x,y)画一条线;可以是连续的几个点。
x: CLose 结束一条线
e: End 结束画图
ar left,top,right,bottom,start(x,y),end(x,y): 逆时针画弧---top,right,bottom,left各位弧的
上右下左边缘界线 四条线限定了圆的位置
wr left,top,right,bottom,start(x,y),end(x,y): 顺时针画弧

主要用到 ar wr

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
.mark{
font-size : 12px;
margin : 0 auto;
display : block;
position : absolute;
text-align : right;
}
</style>
</head>
<body>
<script type="text/javascript" >
var each = function ( object, callback, args ) {
var name, i = 0, length = object.length;
if ( args ) {
args = Array.prototype.slice.call(arguments).slice(2);
if ( length === undefined ) {
for ( name in object )
if ( callback.apply( object[ name ],[name,object[ name ]].concat(args) ) === false )
break;
} else
for ( ; i < length; i++)
if ( callback.apply( object[ i ],[i,object[ i ]].concat(args)) === false ) //
break;
} else {
if ( length === undefined ) {
for ( name in object )
if ( callback.call( object[ name ], name, object[ name ] ) === false )
break;
} else
for ( var value = object[0];
i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
}
return object;
};
window.onload = function(){
document.createStyleSheet().addRule(".vml", "behavior:url(#default#VML);display:inline-block;");
if (!document.namespaces.vml && !+"/v1"){
document.namespaces.add("vml", "urn:schemas-microsoft-com:vml");
}
var vml = {
container : null,
node : null,
init : function(container){
this.container = container;
this.width = container.offsetWidth;
this.height = container.offsetHeight;
return this;
},
$c : function(name){
name = name || 'shape';
this.node = document.createElement('<vml:'+name+' class="vml">');
return this;
},
attr : function(config){
for(var i in config)
this.node.setAttribute(i,config[i]);
return this;
},
css : function(config){
var str = "";
for(var i in config)
str += i == "opacity" ? ("filter:alpha(opacity="+ config[i] * 100+");"):(i+":"+config[i]+";");
this.node.style.cssText = str;
return this;
},
appendTo : function(p){
if(this.node!==null){
p?p.appendChild(this.node):this.container.appendChild(this.node);
}
return this;
}
}

var r = 100,center = [100,100];

function angle(o){
var hudu = Math.PI*2*(o/360),
x = center[0]+ parseFloat(r*Math.sin(hudu)),
y = center[1]+ parseFloat(-r*Math.cos(hudu));
return [x,y];
}

//0到90度
var s = angle(0);
var e = angle(90);

//画饼图
//路径
//var path = 'M 0 0 ar 0 0 ' + 2*r + ' ' + 2*r + ', '+ex+' '+ey+','+sx+' '+sy+' l ' + r + ' ' + r + ' x';
//顺时针
window.path = 'M 0 0 ar 0 0 ' + 2*r + ' ' + 2*r + ', '+e[0]+' '+e[1]+','+s[0]+' '+s[1]+' l ' + r + ' ' + r + ' x';
//逆时针
window.path1 = 'M 0 0 wr 0 0 ' + 2*r + ' ' + 2*r + ', '+e[0]+' '+e[1]+','+s[0]+' '+s[1]+' l ' + r + ' ' + r + ' x';

window.draw = function(p){
document.getElementById('ss').innerHTML = '';
vml.init(document.getElementById('ss')).$c().attr({
strokewidth : 1,
StrokeColor : '#0000ff',
filled : 't',
fillcolor : '#0000ff',
coordsize : 2*r+','+2*r,
path : p || window.path
}).css({
position : "absolute",
left : '0px',
top : '0px',
display : 'inline-block',
width : 2*r+'px',
height : 2*r+'px'
}).appendTo();
}
draw();

}
</script>
<div id='ss' style="height:400px;width:400px; border:1px solid #030; margin:50px; position: relative"></div>
<input type="button" value='逆时针' onclick = 'draw(path)' /><br />
<input type="button" value='顺时针' onclick = 'draw(path1)' />
</body>
</html>

版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:
评论

相关推荐

    vml及Flashvml在线画图用例

    vml在线画图用例,含Flashvml2及Flashvml3的用例。 什么是vml? VML相当于IE里面的画笔,能实现你所想要的图形,而且结合脚本,可以让图形产生动态的效果。VML是微软1999年9月附带IE5.0发布的,在我认为, VML其实是...

    vml入门vml教程vml参考vml实例

    vml入门 vml教程 vml参考 vml实例 从网络上收集的各种vml实例.方便vml入门人员. 也有各种vml图形

    VML实例VML实例

    VML实例VML实例VML实例VML实例VML实例VML实例VML实例VML实例

    FlashVml(闪耀之星)3.0

    VML极道教程 - 最好的VML教程 FlashVml(闪耀之星)3.0 中文版、英文版 - 最强的VML开发工具 推荐解压、浏览方式: 建议解压缩至D或E盘任意位置(防止常重装系统的用户丢失) index.htm文件即是《VML极道教程》的...

    FlashVml(璀灿之星)4.5

    vmljdjc/ 目录包含:《VML极道教程》教程文件内容存储目录 rs/ 目录包含:FlashVml4.5(前台[必要]+后台全部程序[可选删除]、图像、数据资源文件) 说明文档 本文件 可将本压缩包中所有内容,剪切拷贝至您的电脑任意...

    VML技术学习和高级技巧

    VML相当于IE里面的画笔,能实现你所想要的图形,而且结合脚本,可以让图形产生动态的效果。VML是微软1999年9月附带IE5.0发布的,在我认为, VML其实是Word和HTML结合的产物。可以将Word文档另存为HTML,其中的文本和...

    vml柱状图 vml html jquery

    vml柱状图 vml html jquery

    js+vml曲线图代码.rar

    以前发布过一个asp+vml曲线图代码,现在看到一个js+vml曲线图代码 &lt;HTML xmlns:v="urn:schemas-microsoft-com:vml"xmlns:o="urn:schemas-microsoft-com:office:office"&gt; ; charset=gb2312" /&gt; 曲线 &lt;!-- /* 说明:...

    VML帮助文档(CHM)

    VML的全称是Vector Markup Language(矢量可标记语言),矢量的图形,意味着图形可以任意放大缩小而不损失图形的质量,这在制作地图上有很大用途。 VML是微软1999年9月附带IE5.0发布的,在我认为, VML其实是Word和...

    VML中文手册下载

    VML中文手册

    vml fill 渐变vml fill 渐变

    vml fill 渐变vml fill 渐变vml fill 渐变vml fill 渐变vml fill 渐变

    VML极道教程(含实例的学习资料)

    下面介绍一下VML的优点:  基于XML标准  XML是公认拥有无穷生命力的下一代网络标记语言, VML具有先天的优势,它的表示方法简单,易于扩展等等。  支持高质量的矢量图形显示  矢量的图形,意味着图形可以任意...

    VML做的动画,VML学习

    vml学习,提供vml的报表视图展示,有共同爱好者共同成长

    vml+flashVML

    vml+flashVML 网页图形显示、画图、统计图 vml开发手册

    用vml画饼状图用vml画饼状图用vml画饼状图用vml画饼状图

    用vml画饼状图用vml画饼状图用vml画饼状图用vml画饼状图

    VML是跟HTML、CSS、DHTML、JS等等网页设计语言搀杂在一起的

    以前说过,VML是跟HTML、CSS、DHTML、JS等等网页设计语言搀杂在一起的,所以VML文件其实就是一个HTML文件。比如你用记事本写完了VML代码,你可以直接另存为xxx.htm或xxx.html文件放在电脑硬盘的任一个地方,然后找到...

    VML极道教程.VML极道教程.

    VML极道教程.VML极道教程.VML极道教程.VML极道教程.

    VML图像画版

    VML图像画版,用VML画图,生成VML代码

    基于VML的工程图形发布方法的研究

    研究了AutoCAD图形向VML的Web矢量图形的转换方法。在分析了DXF图形文件存储结构的基础上,建立了图元从DXF到VML的映射关系,提出了图层、坐标系、线宽、线型等图形信息的转换方案。基于VB.NET和JavaScript语言实现了...

    VML参考资料/参考文档

    VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料 VML参考资料

Global site tag (gtag.js) - Google Analytics