JavaScript/jQuery 中的叠加层和图像
我试图在 X=100 & 处显示 16 x 16 像素图像Y=100 但我卡住了。该图像将显示在页面上任何内容的顶部。更改顶部和左侧属性不会执行任何操作。
无论我做什么,图像似乎都显示在 pos 0,0 处。
shimDiv.style.position = 'absolute';
shimDiv.style.top = 100;
shimDiv.style.left = 100;
shimDiv.style.width = "1000px"; // todo: change me!
shimDiv.style.height = "1000px"; // todo: change me!
shimDiv.style.zIndex = 3;
document.body.appendChild(shimDiv);
$("#shim").append('<img id="icon" src="../Images/info.png" alt="todo:" />');
I'm trying to show 16 by 16 pixel image at X=100 & Y=100 but am stuck. The image is to be displayed over the top of whatever is on the page. Altering the top and left properties don't do anything.
Whatever I do, the image seems to show up at pos 0,0.
shimDiv.style.position = 'absolute';
shimDiv.style.top = 100;
shimDiv.style.left = 100;
shimDiv.style.width = "1000px"; // todo: change me!
shimDiv.style.height = "1000px"; // todo: change me!
shimDiv.style.zIndex = 3;
document.body.appendChild(shimDiv);
$("#shim").append('<img id="icon" src="../Images/info.png" alt="todo:" />');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为您没有指定
top
和left
位置的单位:That's because you've not specified the units for the
top
andleft
positions:嗯,也许这过于简单化了,但这应该可以满足您的要求:
在您的代码示例中似乎缺少父 div 元素的创建代码,但上面的代码应该是必需的。
希望有帮助...
Hmm, maybe this is an oversimplification, but this should accomplish what you are asking:
It seems in your code sample that the creation code for the parent div element is missing, but the above code should be all that is necessary.
Hope that helps...