惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - 克隆

SVN快速入门(TSVN) C# HttpWebRequest提交数据方式浅析 简单的3个SQL视图搞定所有SqlServer数据库字典 简单统计SQLSERVER用户数据表大小(包括记录总数和空间占用情况) 敏捷开发Scrum 学习笔记,适于移动开发 团队的职责和任务之间的关系 精心收集的jQuery常用的插件1000 24款超实用的Web 2.0风格翻页代码 【转】使用 Entity Framework + ListView + DataPager 实现数据分页 (转)ASP.NET页面打印技术的总结 [转]数据库设计 Step by Step (5) [转]jquery插件弹出div SQLServer2008/2005 生成数据字典SQL语句 SQL HierarchyID 数据类型 OSWorkflow表结构分析 [转]由于项目原因看了一下vml,写了一个Web工作流的设计器雏形! VML流程图 启用IIS的Gzip压缩 IIS压缩
javascript动态创建VML
克隆 · 2011-03-05 · via 博客园 - 克隆

 VML是The Vector Markup Language(矢量可标记语言)的缩写。VML用于将图形数据矢量化的标记语言。这是一种基于 XML 语法的语言,由 AutoDesk 、 Macromedia 和 Microsoft 和 HP 公司向 W3C 提出的方案,于1999年9月附带IE5.0发布的。使用VML可以在IE中绘制矢量图形,所以有人认为VML就是在IE中实现了画笔的功能。要使用VML,我们首先要开辟一个命名空间。

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

它们的作用相当于把HTML标签搞成下面这个样子:

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

接着就是在样式中调用对应的CSS hehavior。静态代码应该是这个样子:

vml\:* { behavior: url(#default#VML) }

网上风传IE8对VML支持不友好,要放弃VML云云,主要原因在于“vml\:*”这个选择器被IE8认为不合法(反面证明IE在努力修正其CSS bug)。由此,人们被迫利用v\:line, v\:rect, v\:roundrect, v\:oval这样子的联合选择器来调用相关的CSS hehavior。不过只要是合法选择器就可以调用CSS hehavior,因此这里用联合选择器实在太累赘了。我想换类选择器是否更合适点呢?试验一下,是无问题的。但仅仅是这样是渲染不出来的,由于IE8已经重写了内核,因此此bug不是hasLayout可以解决的。官方给出答案是使用display:inline-block,这样就可以强逼它继续渲染了。后来我又发现display:block也有此功效,但考虑到内联元素的问题,还是用官方的补丁吧 。至此,开辟命名空与与渲染VML元素的问题就告一段落。

再来看如何动态创建VML元素,由于是非标准,我们就用非标准的createElement方式来创建它。我们需要拼接一个字符串,作为createElement 的参数,它应该包含命名空间与类名。

var createVML = function (tagName) {

    return doc.createElement('<vml:' + tagName + ' class="vml">');

随便做了一个小工具,看看后果如何:

    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 = window.vml = function(name){

    return vml.fn.create(name || "rect");

  vml.fn = vml.prototype = {

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

    appendTo: function(parent){

      if(typeof this.node !== "undefined" && parent.nodeType == 1){

        parent.appendChild(this.node);

        if(bag.hasOwnProperty(i)){

          this.node.setAttribute(i,bag[i])

        if(bag.hasOwnProperty(i))

          str +=  i == "opacity" ? ("filter:alpha(opacity="+ bag[i] * 100+");"):(i+":"+bag[i]+";")

      this.node.style.cssText = str;

最后附上三种创建VML元素的方法:

  1. var VmlElement = document.createElement('<vml:' + tagName + ' class="vml">');

  2. var VmlElement = document.createElement('<' + tagName + ' 

          xmlns="urn:schemas-microsoft.com:vml" class="vml">')

  3. var VmlElement = document.createElement('vml:' + tagName );

    VmlElement.className = "vml";//最后必须把命名空间当作类名加上