简体   繁体   English

固定位置Div可防止焦点在其元素之间移动时滚动

[英]Fixed Position Div prevents scrolling when focus moves betwen its elements

I have two text boxes inside of a div that needs to have its position fixed. 我在div内有两个文本框,需要固定其位置。 Problem is when I am on the first text box and if I tab to the second one, the page does not scroll down to the second because of the fixed position attribute of the div. 问题是当我在第一个文本框上时,如果我跳到第二个文本框,则由于div的position属性固定,页面不会向下滚动到第二个文本框。 Is there any way I can keep the fixed position of the div but still scroll down to the element which has focus? 有什么办法可以保持div的固定位置,但仍然向下滚动到具有焦点的元素?

<div style="width:100%;height:100%;position:fixed;">
<input id="FirstName"> Lots of padding goes here
<input id="LastName">
 </div>

For the full code please see my fiddle https://jsfiddle.net/43dLktss/1/ 有关完整代码,请参见我的小提琴https://jsfiddle.net/43dLktss/1/

I am thinking maybe jQuery animate on the focus event handler of the text boxes? 我想也许jQuery动画在文本框的焦点事件处理程序上?

No additional javascript/jQuery necessary. 无需其他javascript / jQuery。 Add an inner div , with relative position, height:100%; 添加一个内部div ,相对位置, height:100%; and overflow:scroll; overflow:scroll;

<div style="width:100%;height:100%;position:fixed;">
  <div style="height:100%;position:relative;overflow:scroll;">
    <input id="FirstName"> lots of padding here<input id="LastName">
  </div>
</div>

See the updated fiddle: https://jsfiddle.net/sablefoste/s0jmzph0/ 请参阅更新的提琴: https//jsfiddle.net/sablefoste/s0jmzph0/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM