脚本自动完成器结果列表位置问题

发布于 2024-11-29 19:22:08 字数 1495 浏览 1 评论 0 原文

我正在使用 Scripatculous 自动完成器 1.9.0。我的问题是结果列表 div 的位置在 Chrome 和 Firefox 中不正确,但在 IE 中有效。结果列表 div 显示在文本框的顶部。我能够修改controls.js并解决问题,但我想知道我是否对样式表做错了什么。这是我的代码:

style.css:
div#autocomplete
{
  position: relative;
}

input#query {
  width:500px;
}

div#answerlist {
  width:500px;
  max-height:700px;
  overflow-y:scroll;
  overflow-x:auto;
  border:1px solid #CCCCCC;
}

index.phtml:

<div id="webphone" style="width: 1000px">
<center>
<label>Search:</label>
<input type="text" name="query" id="query"></input>
</center>
<div id="answerlist"></div>
</div>

<script type="text/javascript">
new Ajax.Autocompleter("query","answerlist","index/search", {frequency: 0.5, minChars: 1});
</script>

我尝试取消嵌套 div 和所有元素的“位置”选项的许多其他变体。什么都没起作用。

然后,我开始使用controls.js Autocompleter.create 函数和onShow 函数:

 controls.js:

 function(element, update){
    if(!update.style.position || update.style.position=='absolute') {
      /***alert(update.style.position);***/
      update.style.position = 'absolute';
      Position.clone(element, update, {
       setHeight: false,
        offsetTop: element.offsetHeight
      });
    }
    Effect.Appear(update,{duration:0.15});
  };

首先,alert 函数总是返回一个空字符串,即使我明确地将答案列表的位置样式设置为相对或绝对。其次,即使脚本明确地使位置绝对并定位元素,但最终位置是不正确的!我是唯一经历过这种事的人吗?我在linux和windows上尝试了很多版本的chrome和firefox。我一定是做错了什么。当然,我可以通过注释掉这部分代码并使用绝对定位来定位 div 元素来解决该问题。但我宁愿不这样做......

I am using Scripatculous Autocompleter 1.9.0. My problem is that the position of the result list div is incorrect in Chrome and Firefox, but works in IE. The result list div appears on top of the text box. I was able to modify controls.js and fix the problem, but I am wondering if I am doing something wrong with the style sheet. Here is my code:

style.css:
div#autocomplete
{
  position: relative;
}

input#query {
  width:500px;
}

div#answerlist {
  width:500px;
  max-height:700px;
  overflow-y:scroll;
  overflow-x:auto;
  border:1px solid #CCCCCC;
}

index.phtml:

<div id="webphone" style="width: 1000px">
<center>
<label>Search:</label>
<input type="text" name="query" id="query"></input>
</center>
<div id="answerlist"></div>
</div>

<script type="text/javascript">
new Ajax.Autocompleter("query","answerlist","index/search", {frequency: 0.5, minChars: 1});
</script>

I tried un-nesting the divs and many other variations of "position" options for all elements. Nothing worked.

Then, I started playing with controls.js Autocompleter.create function, and the onShow function:

 controls.js:

 function(element, update){
    if(!update.style.position || update.style.position=='absolute') {
      /***alert(update.style.position);***/
      update.style.position = 'absolute';
      Position.clone(element, update, {
       setHeight: false,
        offsetTop: element.offsetHeight
      });
    }
    Effect.Appear(update,{duration:0.15});
  };

First, the alert function always returns an empty string, even if I explicitly set the position style of answerlist to relative or absolute. Second, even though the script explicitly makes the position absolute and positions the element, the final position is incorrect! Am I the only one experiencing this? I tried many versions of chrome and firefox, on both linux and windows. I must be doing something wrong. Of course I can fix the problem by commenting out this part of the code and positioning the div element using absolute positioning. But I prefer not to do that...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路弥 2024-12-06 19:22:08

在解决同样的问题后,我找到了解决方案并在 https://prototype.lighthouseapp.com/projects/8886/tickets/1286-error-in-elementcloneposition#ticket-1286-1

那里描述了修复,但基本上是 Element。 clonePosition 具有以下内容:

if (parent == document.body) {
    delta[0] -= document.body.offsetLeft;
    delta[1] -= document.body.offsetTop;
}

必须替换为:

if (parent == document.body) {
    var parentOffset = Element.viewportOffset(parent);
    delta[0] -= parentOffset[0];
    delta[1] -= parentOffset[1];
}

After struggling with the same issue, I found the solution and opened a ticket at https://prototype.lighthouseapp.com/projects/8886/tickets/1286-error-in-elementcloneposition#ticket-1286-1

The fix is described there, but basically, Element.clonePosition has the following:

if (parent == document.body) {
    delta[0] -= document.body.offsetLeft;
    delta[1] -= document.body.offsetTop;
}

That has to be replaced by:

if (parent == document.body) {
    var parentOffset = Element.viewportOffset(parent);
    delta[0] -= parentOffset[0];
    delta[1] -= parentOffset[1];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文