jQuery UI Autocomplete with scrollbar z-index help

女生的网名这么多〃 提交于 2019-12-13 16:01:45

问题


I have a textbox that I am attaching jQuery UI's Autocomplete functionality to and I am using CSS to give it a max height via the example here. My problem is that doing this causes the z-index problem that bgiframe solves to come back again, but in a different way. The initial autocomplete menu is above all the controls underneath it, but when I begin to scroll the autocomplete menu falls behind them.

Any suggestions?

EDIT:

This is purely an IE6 bug.

As you can see, after scrolling down the autocomplete falls behind the other controls.


回答1:


I could solve the problem by replacing offsetHeight by scrollHeight in the following line (from jquery.bgiframe.js) :

height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+

This change solved the bug for the autocomplete fields with vertical scrollbars. I could not spot any regression in other kinds of dialogs (but I did not run extensive tests).




回答2:


You need to reverse the z-index order of the form elements (or their containers) using javascript. I.e., "Social Worker" has the lowest, "DX Code" the highest z-index.




回答3:


You could change the offsetHeight to scrollHeight, like Siggen says, but I have encountered problems when there is only 1 result returned from the autocomplete. The 1 result is squished into a window that only like 2 pxs high. I found a fix though. When you have a data.length<2, you should use the offsetHeight, rather than the scrollHeight.

You have to modify autocomplete.js.

Locate this code:
if($.fn.bgiframe)list.bgiframe();

And make it this:

if($.fn.bgiframe){
    if(data.length<2)
       list.bgiframe({height:'expression(this.parentNode.offsetHeight+\'px\')'});
    else 
       list.bgiframe();
}

Remember, this code should be used in combination with Siggen's fix.




回答4:


I have used a combination of both parameter for the height like this:

'height:'+(s.height=='auto'?'expression(Math.max(this.parentNode.offsetHeight,this.parentNode.scrollHeight)+\'px\')':prop(s.height))+';'

Look at the max function. Now it is good with no scroll bar (shorter list and longer list as well)

and now the autocomplete component looks perfect in IE6.



来源:https://stackoverflow.com/questions/4674558/jquery-ui-autocomplete-with-scrollbar-z-index-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!