重新定位 Jquery UI 自动完成结果框

我正在使用 Jquery UI 自动完成插件作为直接搜索词建议工具.除了我无法移动结果框外,它已启动并运行,没有任何问题.我基本上需要将它向左移动 20 像素,向下移动 4 像素.我试图覆盖 Jquery UI CSS,但无法重新定位框.

I am using the Jquery UI Autocomplete plugin for a straight forward search term suggestion tool. It is up and running with no problems except that I cannot move the results box. I basically need to move it 20 pixels to the left and 4 pixels down. I have attempted to overwrite the Jquery UI CSS, but have not been able to reposition the box.

非常感谢有此问题经验的人提供任何帮助.

Any help from someone experienced with this issue would be greatly appreciated.

推荐答案

这里有一种方法可以做到这一点,点击 open 事件并在该事件发生时更改菜单的位置:

Here's one way you could do it, tapping into the open event and changing the position of the menu when that event occurs:

$("#autocomplete").autocomplete({
    appendTo: "#results",
    open: function() {
        var position = $("#results").position(),
            left = position.left, top = position.top;

        $("#results > ul").css({left: left + 20 + "px",
                                top: top + 4 + "px" });

    }
});

我还使用 appendTo 选项来轻松查找包含菜单的 ul.不过,您可以在没有此选项的情况下执行此操作.

I'm also using the appendTo option to make finding the ul that contains the menu easily. You could do it without this option though.

这是一个工作示例:http://jsfiddle.net/9QmPr/

相关文章