如何根据客户端屏幕定位web用户控件

How to position web user control according to client screen

本文关键字:web 用户 控件 定位 屏幕 何根 客户端      更新时间:2023-09-26

我正在使用asp和Ajax控件构建一个多列组合框。它非常好用。如何使用javascript根据客户端屏幕和用户控制在页面上的位置设置下拉列表的大小和位置。

您需要使用元素的.style.leftstyle.top等属性,以及document.body元素的.scrollHeight。对于尺寸,您将使用.style.height.style.width

在CSS中,元素必须使用position:absolute进行样式设置。通过将父对象设置为position:relative,可以使其相对于父对象的绝对位置。

然后,Javascript可能看起来像:

yourelement.style.top= document.body.scrollHeight + 100 + 'px';

将把元素的上边缘从窗口的滚动高度放置100px。


每个元素的绝对位置和位置可以使用进行控制

yourelement.style.top = ...'px';
yourelement.style.bottom = ...'px';
yourelement.style.left = ...'px';
yourelement.style.right = ...'px';
yourelement.style.width = ...'px';
yourelement.style.height = ...'px';

要获得不同的高度和宽度,可以使用document.scrollHeightdocument.documentElement.scrollHeightdocument.body.scrollHeight(取决于浏览器)。它们也有.scrollWidth