Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,看看google.com您的 iPhone 或 Android 设备。当我点击搜索文本字段时,它会自动直接转到手机屏幕的顶部,从而允许最大的自动完成列表项。
google.com
在不影响非移动用户的情况下,是否有一个简洁、简单的技巧可以用 JS 做到这一点?
$(document).on('focus click', 'input', function() { if($(window).width() <= 767) { $('html, body').animate({ scrollTop: $('input').offset().top }, 'fast'); } });
让它工作,但.animate()在 iPhone 自己的居中后会有一点点卡顿。欢迎改进。
.animate()