[英]How to arrange multiple html elements based on x-y coordinates and width-height?
I am developing a digital signage application in HTML5 in which I will have a screen which will be playing/showing various medias setup by user. 我正在开发HTML5中的数字标牌应用程序,我将在其中显示一个屏幕,该屏幕将播放/显示用户设置的各种媒体。 I have multiple elements like video, images, widgets, ticker etc. I have xy axis of elements and their height/width, I want to arrange them precisely based on the information given. 我有多个元素,如视频,图像,小部件,自动收报机等。我有xy轴的元素和它们的高度/宽度,我想根据给定的信息精确排列它们。 I will get data in either xml/json. 我将在xml / json中获取数据。
I have tried with plain CSS, but it not working as expected. 我尝试使用纯CSS,但它没有按预期工作。 I tried SVG and Canvas, but they do not support all the html elemnts. 我尝试过SVG和Canvas,但它们并不支持所有的html元素。
You can simply position elements using absolute
from Javascript: 您可以使用Javascript中的absolute
来定位元素:
function absElement(type, x, y, w, h) {
let d = document.createElement(type);
d.style.position = "absolute";
d.style.left = x + "px";
d.style.top = y + "px";
d.style.width = w + "px";
d.style.height = h + "px";
document.body.appendChild(d);
return d;
}
Then you can use it like 那你可以像使用它一样
absElement("img", 100, 200, 400, 200).src = "myimage.jpg";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.