使用 javascript 添加 VML 元素(图像)

发布于 2024-09-10 21:47:19 字数 1083 浏览 2 评论 0原文

您好,我一直在尝试使用 javascript 添加 VML 图像元素。 现在这是我用来生成这些图像的内容:

function add_tools()
{       
var elemm = document.createElement('rvml:image'); 
elemm.setAttribute('src', 'pic.png');
elemm.setAttribute('id', 'gogo');
elemm.setAttribute('class', 'rvml');
document.body.appendChild(elemm);   

document.getElementById('gogo').style.position='absolute';
document.getElementById('gogo').style.width=55;
document.getElementById('gogo').style.height=55;
document.getElementById('gogo').style.top=200;
document.getElementById('gogo').style.left=300;
document.getElementById('gogo').style.rotation=200;
document.getElementById('gogo').style.display = "block"; 
}

通常当我生成 vml 图像元素时,HTML 代码应该类似于:

<rvml:image style="POSITION:absolute; WIDTH:55px; HEIGHT:55px; TOP:0px; LEFT:0px; rotation:0;" src="pic.png" id=gogo class=rvml>

现在上面的 javascript 函数适用于 HTML 元素。 但是当我用它来生成VML元素时。生成的元素不会显示在浏览器中。但是当我检查 document.body.innerHTML 时。我可以看到该元素已实际创建。但它没有显示..

有什么想法吗? 有没有什么方法可以用来用 javascript 刷新或重绘元素。或任何我可以用来解决这个问题的东西。

谢谢

hi I've been trying to add VML image elements using javascript.
now here is what I'm using to generate these images:

function add_tools()
{       
var elemm = document.createElement('rvml:image'); 
elemm.setAttribute('src', 'pic.png');
elemm.setAttribute('id', 'gogo');
elemm.setAttribute('class', 'rvml');
document.body.appendChild(elemm);   

document.getElementById('gogo').style.position='absolute';
document.getElementById('gogo').style.width=55;
document.getElementById('gogo').style.height=55;
document.getElementById('gogo').style.top=200;
document.getElementById('gogo').style.left=300;
document.getElementById('gogo').style.rotation=200;
document.getElementById('gogo').style.display = "block"; 
}

usually when I generate vml image element the HTML code should look somthing like:

<rvml:image style="POSITION:absolute; WIDTH:55px; HEIGHT:55px; TOP:0px; LEFT:0px; rotation:0;" src="pic.png" id=gogo class=rvml>

now the above javascript function works with HTML elements.
but when I use it to generate VML elements. the generated element doesn't show in the browser. but when I check document.body.innerHTML. I can see that the element has been actually created. but its not showing..

any ideas?
is there any method I can use to refresh or redraw elements with javascript. or anything I can use to fix this.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不打扰别人 2024-09-17 21:47:19

我为此无休止地挣扎,最后我用填充代替:

<div style="position:relative">
  <vml:rect stroked="f" style="position:absolute"> 
    <vml:fill type="tile" aspect="ignore" src="pathto.png" style="position:absolute">  
    </vml:fill>
  <vml:rect> 
</div>

似乎需要绝对位置,因此需要包含 div 的相对位置。

有关更多信息,请查看 jQuery 的 superpng 插件,该插件使用此技术进行 png alpha 替换。

I struggled endlessly with this, and in the end I used a fill instead:

<div style="position:relative">
  <vml:rect stroked="f" style="position:absolute"> 
    <vml:fill type="tile" aspect="ignore" src="pathto.png" style="position:absolute">  
    </vml:fill>
  <vml:rect> 
</div>

It seems that position absolute is required, hence the need for a position relative containing div.

For more info check out the superpng plug-in for jQuery which uses this technique for png alpha replacement.

装纯掩盖桑 2024-09-17 21:47:19

呃。像往常一样自己修复了它......

function add_tools()
{   
var elemm = document.createElement('rvml:image'); 
elemm.src = 'pic.png';
elemm.className = 'rvml';
document.body.appendChild(elemm);
elemm.id = "gogo";
elemm.style.position='absolute';
elemm.style.width=55;
elemm.style.height=55;
elemm.style.top=200;
elemm.style.left=300;
elemm.style.rotation=200; 
}

setAttribute 函数似乎没有改变元素的状态。
但我仍然遇到事件问题。现在,如果我想使用:

elemm.onload = "alert('coco')";

当我运行绘制元素的 javascript 函数时,应该触发此操作。
但我没有让警报框正常工作。嗯,有点奇怪。我检查了innerHTML,我可以在那里看到它。

uh. fixed it myself as usual...

function add_tools()
{   
var elemm = document.createElement('rvml:image'); 
elemm.src = 'pic.png';
elemm.className = 'rvml';
document.body.appendChild(elemm);
elemm.id = "gogo";
elemm.style.position='absolute';
elemm.style.width=55;
elemm.style.height=55;
elemm.style.top=200;
elemm.style.left=300;
elemm.style.rotation=200; 
}

it seems like the setAttribute function is not changing the status of the element.
but still I'm having problem with events. now if I want to use:

elemm.onload = "alert('coco')";

this should be triggered when I run the javascript function which will draw the element.
but I'm not getting that alert box to be workin. hmm its kindda weird. I checked the innerHTML i can see it right there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文