我有一个带有建议框的文本输入,当输入内容时,该建议框会出现在输入下方。问题是当页面缩放时,框有时会出现在稍微不同的位置(1-3 像素)。有没有办法保证,无论页面比例如何,建议框始终保持相对于输入字段底线的左边0px和顶部0px?谢谢。
tBox = $('#textBox')[0];
$('#suggestionBox').css({
width: "151px",
border: "1px solid grey",
position: "absolute",
top: (tBox.offsetTop + tBox.offsetHeight) + "px",
left: tBox.offsetLeft + "px"
});
<input type="text" id="textBox" />
<div id="suggestionBox" style="display:none;">suggesion</div>
最佳答案
你试过用这个http://docs.jquery.com/UI/API/1.8/Position吗? ?
$("#suggestionBox").position({
my: "left top",
at: "left bottom",
of: $('#textBox')
});
关于javascript - 保持建议框始终直接在文本框下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16037667/