admin管理员组文章数量:1026958
My app has a pretty unique style for all the popups that occur, and I can't make the generated jQuery UI Autoplete html work to fit into that style. What I'd like to do is place the autoplete into a pre-made container that's configured to drop in.
However, when I use the appendTo option, the list doesn't appear, and it seems to be because the style is positioning it somewhere outside the visible area of the popup.
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
appendTo: '#popover-hook'
});
Everything works fine when appendTo isn't set.
So: is there a way to put the contents of the autoplete into another div that's placed correctly already?
My app has a pretty unique style for all the popups that occur, and I can't make the generated jQuery UI Autoplete html work to fit into that style. What I'd like to do is place the autoplete into a pre-made container that's configured to drop in.
However, when I use the appendTo option, the list doesn't appear, and it seems to be because the style is positioning it somewhere outside the visible area of the popup.
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
appendTo: '#popover-hook'
});
Everything works fine when appendTo isn't set.
So: is there a way to put the contents of the autoplete into another div that's placed correctly already?
Share Improve this question asked May 8, 2011 at 17:56 Tim SullivanTim Sullivan 16.9k12 gold badges75 silver badges120 bronze badges 2-
What does the markup for the existing
div
look like? How is it styled? – Andrew Whitaker Commented May 8, 2011 at 18:34 - can you setup a jsfiddle with the current code? – ariel Commented May 9, 2011 at 1:41
1 Answer
Reset to default 4The autoplete widget creates a UL element containing the suggestions. The appendTo
option specifies where that UL element gets inserted into the DOM. By default, the UL element is appended to the BODY. Styles are then used to position the UL in the correct location.
The autoplete dropdown adds the ui-autoplete
and ui-menu-item classes
. You should be able to apply your style to those classes. If not, can you give us an essence of the unique styles that?
For positioning, you can override the styling of the UL after the open event fires. Here's an example of absolute positioning:
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
open: function(event, ui) {
$(".ui-autoplete").css("position", "absolute");
$(".ui-autoplete").css("top", "100px");
$(".ui-autoplete").css("left", "100px");
}
});
Here is an example of positioning inside a container element:
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
appendTo: "#container",
open: function(event, ui) {
$(".ui-autoplete").css("position", "relative");
$(".ui-autoplete").css("top", "0px");
$(".ui-autoplete").css("left", "0px");
}
});
My app has a pretty unique style for all the popups that occur, and I can't make the generated jQuery UI Autoplete html work to fit into that style. What I'd like to do is place the autoplete into a pre-made container that's configured to drop in.
However, when I use the appendTo option, the list doesn't appear, and it seems to be because the style is positioning it somewhere outside the visible area of the popup.
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
appendTo: '#popover-hook'
});
Everything works fine when appendTo isn't set.
So: is there a way to put the contents of the autoplete into another div that's placed correctly already?
My app has a pretty unique style for all the popups that occur, and I can't make the generated jQuery UI Autoplete html work to fit into that style. What I'd like to do is place the autoplete into a pre-made container that's configured to drop in.
However, when I use the appendTo option, the list doesn't appear, and it seems to be because the style is positioning it somewhere outside the visible area of the popup.
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
appendTo: '#popover-hook'
});
Everything works fine when appendTo isn't set.
So: is there a way to put the contents of the autoplete into another div that's placed correctly already?
Share Improve this question asked May 8, 2011 at 17:56 Tim SullivanTim Sullivan 16.9k12 gold badges75 silver badges120 bronze badges 2-
What does the markup for the existing
div
look like? How is it styled? – Andrew Whitaker Commented May 8, 2011 at 18:34 - can you setup a jsfiddle with the current code? – ariel Commented May 9, 2011 at 1:41
1 Answer
Reset to default 4The autoplete widget creates a UL element containing the suggestions. The appendTo
option specifies where that UL element gets inserted into the DOM. By default, the UL element is appended to the BODY. Styles are then used to position the UL in the correct location.
The autoplete dropdown adds the ui-autoplete
and ui-menu-item classes
. You should be able to apply your style to those classes. If not, can you give us an essence of the unique styles that?
For positioning, you can override the styling of the UL after the open event fires. Here's an example of absolute positioning:
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
open: function(event, ui) {
$(".ui-autoplete").css("position", "absolute");
$(".ui-autoplete").css("top", "100px");
$(".ui-autoplete").css("left", "100px");
}
});
Here is an example of positioning inside a container element:
$('#name').autoplete({
minLength: 0,
source:"this,that,these,those".split(','),
appendTo: "#container",
open: function(event, ui) {
$(".ui-autoplete").css("position", "relative");
$(".ui-autoplete").css("top", "0px");
$(".ui-autoplete").css("left", "0px");
}
});
本文标签: javascriptjquery UI AutoCompleteembedding the list in another containerStack Overflow
版权声明:本文标题:javascript - jquery UI AutoComplete - embedding the list in another container - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745653389a2161452.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论