防止<输入>在 iPhone 上滚动屏幕的元素? [英] Preventing an <input> element from scrolling the screen on iPhone?
问题描述
我的网页上有几个 元素.我正在使用 jQTouch,并且我试图始终保持全屏;也就是说,水平滚动是不好的.每当我单击
<input>
元素时,页面都会向右滚动,在屏幕右侧显示一个黑色边框,并使所有内容都偏离中心.输入从屏幕左侧偏移,它们从页面中间的某处开始.
I have several <input type="number">
elements on my webpage. I'm using jQTouch, and I'm trying to stay fullscreen at all times; that is, horizontal scrolling is bad. Whenever I click an <input>
element, the page scrolls right, showing a black border on the right of the screen and de-centering everything. The inputs are offset from the left of the screen, and they begin somewhere toward the middle of the page.
如何防止在焦点上滚动?
How can I prevent this scrolling on focus?
推荐答案
我刚刚在这篇文章中找到了这个问题的解决方案 停止从焦点滚动页面
I just found the solution to this problem in this post Stop page scrolling from focus
只需将 onFocus="window.scrollTo(0, 0);"
添加到您的输入字段即可!(在 iPad 上用 和
尝试过,但我很确定它会在iPhone也是.)
Just add onFocus="window.scrollTo(0, 0);"
to your input field and you're done!
(Tried it with <textarea>
and <input type="text" />
on the iPad, but I'm pretty sure it'll work on the iPhone too.)
我担心滚动会显示为闪烁或其他东西,但幸运的是事实并非如此!
I was afraid the scrolling would be visible as a flicker or something, but fortunately that is not the case!
这篇关于防止<输入>在 iPhone 上滚动屏幕的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!