Skip to content

Instantly share code, notes, and snippets.

@berkin
Created November 18, 2016 07:41
Show Gist options
  • Save berkin/2904eff5d0941491da2a717e3cdcdf39 to your computer and use it in GitHub Desktop.
Save berkin/2904eff5d0941491da2a717e3cdcdf39 to your computer and use it in GitHub Desktop.
import scrollParent from './scrolll-parent.js';
if (/Android [4-6]/.test(navigator.appVersion)) {
window.addEventListener('resize', () => {
if (document.activeElement.tagName === 'INPUT') {
window.setTimeout(() => {
const el = document.activeElement;
const rect = el.getBoundingClientRect();
const container = scrollParent(el);
const containerHeight = container.clientHeight;
// scroll to center of visible area
//console.log(`${rect.top}, ${rect.height}, ${containerHeight}`);
container.scrollTop = (rect.top + container.scrollTop + (rect.height / 2)) - (containerHeight / 2);
}, 0);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment