【问题标题】:Flex - How do I get the absolute X and Y coordinate including HTML offset?Flex - 如何获得绝对 X 和 Y 坐标,包括 HTML 偏移量?
【发布时间】:2010-02-18 05:25:06
【问题描述】:

我正在使用 Flex 通过 ExternalInterface 调用 JS 函数,这需要绝对 X 和 Y 坐标来创建弹出菜单。 Flex 应用程序显示在 HTML 页面的中心,因此需要考虑 HTML X 和 Y 偏移量。

我曾尝试使用 LocalToGlobal 和 ContentToGlobal 函数,但这些只是给我相对于 Flex 应用程序的 X 和 Y 坐标,它没有考虑将 Flex 应用程序置于中心的 HTML X 和 Y 偏移量页面或不同的屏幕分辨率。

是使用 JavaScript 检索 HTML X 和 Y 偏移的最佳方法吗?有没有我可以使用的 Flex 函数来提供基于 HTML 页面的绝对 X 和 Y 坐标?

谢谢!

【问题讨论】:

  • 弹出菜单是 flex 还是 html?如果它在 flex 中,并且如果 flex 已经在 html 的中心,为什么你需要 swf 的 x/y 值?你不能只使用localtoglobal函数吗?

标签: javascript html apache-flex coordinates


【解决方案1】:

如果我的理解正确,听起来像:

  • 您在 HTML 页面的中心有一个小型 Flex 应用程序
  • 在某些情况下,您想创建一个 HTML 弹出窗口(新的浏览器弹出窗口)。
  • 该弹出窗口应位于 HTML 页面的中心。

如果正确,则不需要使用 localToGlobal 或 globalToLocal;您只是在寻找浏览器视口范围。这是我目前用来放置与浏览器边界相关的项目的方法(所有这些都是 javascript):

function getBrowserBounds()
{
        var size = [0, 0]; 
        if (typeof window.innerWidth != "undefined") { 
            size = [window.innerWidth, window.innerHeight];
        } 
        else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
            size = [document.documentElement.clientWidth, document.documentElement.clientHeight]; 
        }
        else {
            size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight]; 
        }
        var bounds = null;
        if (navigator.userAgent.indexOf("MSIE") != -1) // Internet Explorer
            bounds = [window.screenLeft, window.screenTop, size[0], size[1]];
        else
            bounds = [window.screenX, window.screenY, size[0], size[1]];
        var width = bounds[0] + (bounds[2]/2);
        var height = bounds[1] + (bounds[3]/2);
        return bounds;
}

返回浏览器视口的边界。从那里,您可以创建一个位于浏览器中心的弹出窗口,无论浏览器在笔记本电脑/台式机屏幕范围内的任何位置,使用以下命令:

function centerPopup(windowHeight, windowWidth, windowName, windowUri)
{
    var bounds = getBrowserBounds();
    var centerWidth = bounds[0] + ((bounds[2] - windowWidth) / 2);
    var centerHeight = bounds[1] + ((bounds[3] - windowHeight) / 2);

    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);

    newWindow.focus();
    return newWindow.name;
}

让我知道这是否有效。

最好, 兰斯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-18
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2018-09-20
    • 1970-01-01
    相关资源
    最近更新 更多