简体   繁体   English

如何根据xy坐标和width-height排列多个html元素?

[英]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.

相关问题 xy坐标和html5中sprite图片的宽度和高度 - x-y coordinates & width-height of an image from sprite in html5 根据x和y坐标以及javascript中的宽度和高度值计算面积 - calculate an area based on x and y coordinates and width and height values in javascript 如何在使用 JSPDF 新 html API 从 html 生成 pdf 时给出宽度、高度、x 和 y 坐标 - How to give width, height, x and y coordinates in generating pdf from html using JSPDF new html API JS“窗口”宽高与“屏幕”宽高? - JS “Window” width-height vs “screen” width-height? XY坐标可以用作超过XY坐标的值容器 - can X-Y coordinates be used as value containers for more than X-Y coordinates 如何获取HTML页面上所有链接的X,Y宽度和高度 - How to get X,Y width and height of all the links on an HTML page 如何在ChartJS中使用溢出滚动修复图表图例宽度 - 高度 - How to fix chart Legends width-height with overflow scroll in ChartJS 将鼠标悬停在图像上时,如何显示带有xy坐标的十字光标? - How could I display a crosshair cursor with x-y coordinates when hovering over an image? 从给定的坐标(x,y)计算边界框的宽度和高度 - Calculate bounding box width and height from given coordinates(x,y) 如何使用 Javascript 在浏览器中按 XY 坐标定位? - How do I use Javascript to locate by X-Y Coordinates in my browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM