問題描述
我正在使用 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/
這篇關于重新定位 Jquery UI 自動完成結果框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!