admin管理员组文章数量:1429876
Is it possible in javascript to superimpose a transparent-background image upon another image? Let's say you have a website with a bunch of product pictures, gizmos and widgets and thingamajigs, and some of these products have been recalled by the manufacturer and upon those images you want to superimpose the Do-Not-Enter sign (circle-with-slash icon) -- in a transparent manner so the original image still shows through. Can that be done? The goal is to not have to edit the images.
Am I going down the right track to put the transparent-background image in a DIV without opacity and to size the transparent-background image and its container DIV according to the size of the original image using clientWidth and clientHeight, and then position the DIV on top of the original image? If the window is resized and the layout changes dynamically, how/when would the superimposed DIV be told to move to the new location of the original image? There's nothing like a LayoutChangedEvent is there? Would the original image's position have to be checked repeatedly using setInterval?
Is it possible in javascript to superimpose a transparent-background image upon another image? Let's say you have a website with a bunch of product pictures, gizmos and widgets and thingamajigs, and some of these products have been recalled by the manufacturer and upon those images you want to superimpose the Do-Not-Enter sign (circle-with-slash icon) -- in a transparent manner so the original image still shows through. Can that be done? The goal is to not have to edit the images.
Am I going down the right track to put the transparent-background image in a DIV without opacity and to size the transparent-background image and its container DIV according to the size of the original image using clientWidth and clientHeight, and then position the DIV on top of the original image? If the window is resized and the layout changes dynamically, how/when would the superimposed DIV be told to move to the new location of the original image? There's nothing like a LayoutChangedEvent is there? Would the original image's position have to be checked repeatedly using setInterval?
Share Improve this question asked Apr 21, 2011 at 17:47 TimTim 8,93931 gold badges111 silver badges193 bronze badges1 Answer
Reset to default 5You don't need Javascript for this, you can easily acplish this with CSS.
The example below is very simple. If you wrap the product image in a container element and set that container to position: relative
then you are able to position child elements relative to that container. This way, if the window is resized it doesn't matter.
View a working demo on jsFiddle: http://jsfiddle/VNqSd/2/
HTML
<div class="container">
<img src="http://nontalk.s3.amazonaws./product.png"
width="100" height="100" />
<img src="http://nontalk.s3.amazonaws./overlay.png"
class="overlay" width="100" height="100" />
</div>
CSS
.container {
position: relative;
}
.overlay {
position: absolute;
left:0;
top: 0;
z-index: 999;
}
本文标签: superimpose one transparent image on another with javascriptStack Overflow
版权声明:本文标题:superimpose one transparent image on another with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745489950a2660558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论