在使用Jquery自动完成功能时,特别是在推荐的术语列表输出后,如果更改浏览器窗口的大小,列表的整个位置将在执行更改的相反方向上移动。 有没有办法避免这种情况发生?
JS档案:
function autocomplet() {
$("input#ui-autocomplete-input").autocomplete({
minLength: 2,
source: '/store.json',
focus: function(event, ui){
$("input#ui-autocomplete-input").val(ui.item.product.name);
return false;
},
select: function(event, ui){
$("input#ui-autocomplete-input").val(ui.item.product.name);
$("input#ui-autocomplete-input").val(ui.item.product.name);
return false;
}
// source: '<%= products_path(:json) %>'
// source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
}).data("autocomplete")._renderItem = function(ul, item){
return $("<li></li>").data("item.autocomplete", item).append("<a>"+item.product.name+"</a>").appendTo(ul);
}
};
$(document).ready(autocomplet);
CSS文件:
body {
font-size: 62.5%;
}
table {
font-size: 1em;
}
tr:first-child{
font-size: 4em;
font-weight: bold;
}
td{
width: 100px;
height: 30px;
}
/* Site
-------------------------------- */
body {
font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
}
/* Normal
-------------------------------- */
.normal h3,
.normal h4 {
margin: 0;
font-weight: normal;
}
.normal h3 {
padding: 0 0 9px;
font-size: 1.8em;
}
.normal h4 {
padding-bottom: 21px;
border-bottom: 1px dashed #999;
font-size: 1.2em;
font-weight: bold;
}
.normal p {
font-size: 1.2em;
}
ul {
list-style: none;
border:none;
}
/* Misc visuals
----------------------------------*/
/* Search textbox*/
fieldset.search{
border:none;
width: 285px;
}
.search input.btn:hover{
background: #FFFFFF no-repeat left;
}
.search input.btn{
border:none;
font-size: 1.2em;
width: 50px;
height: 40px;
cursor: pointer;
background: #fbc900;
}
.search input.box{
border-top:5px solid #fff;
border-bottom:5px solid #fff;
border-left:0px;
color: #fff;
font-size: 1.2em;
width: 190px;
height: 38px;
text-indent:8px;
background: #D63737;
}
.search input.box:focus{
outline-width:0;
}
.search button.btn:hover{
background: #fbc900 no-repeat bottom right;
}
/* Corner radius */
.ui-state-focus, .ui-widget-content, .ui-state-focus, .ui-widget-header, .ui-state-focus {
background: #DADADA;
color: #212121;
cursor: pointer;
width:206px;
}
.ui-corner-all {
position:relative;
background-color: #213216;
width: 206px;
}
.ui-active-menuitem, .ui-state-hover, .ui-state-highlight{
height: 38px;
background:#D63737;
cursor:pointer;
width: 206px;
}
.ui-menu-item{
font-size: 1em;
text-indent:9px;
height:38px;
width:206px;
}
答案 0 :(得分:1)
我发现这是为了回答我的问题:
答案 1 :(得分:1)
您只需在jquery.gui.css
中找到以下代码.ui-menu .ui-menu-item { margin:0; padding: 0; zoom: 0; float: left; clear: left; width: 100%; }
并在此处更改字体大小..例如“font-size:12px”
答案 2 :(得分:1)
您可能还想使用此功能:
.ui-autocomplete
{
max-height: 300px !important;
}
限制结果弹出窗口的大小