const ua = navigator . userAgent ; const iOS = /iPad|iPhone|iPod/ . test ( ua ) ; function uaIncludes ( str ) { return ua . indexOf ( str ) !== - 1 ; } function testScrollType ( ) { if ( iOS ) { if ( uaIncludes ( 'Safari/' ) || /OS 11_[0-3]\D/ . test ( ua ) ) { /**
             * 不处理
             * - Safari
             * - iOS 11.0-11.3（`scrollTop`/`scrolIntoView` 有 bug）
             */ return 0 ; } return 1 ; } return 2 ; } export default function riseInput ( input , target ) { const scrollType = testScrollType ( ) ; let scrollTimer ; if ( ! target ) { target = input ; } const scrollIntoView = ( ) => { if ( scrollType === 0 ) return ; if ( scrollType === 1 ) { document . body . scrollTop = document . body . scrollHeight ; } else { target . scrollIntoView ( false ) ; } } ; input . addEventListener ( 'focus' , ( ) => { setTimeout ( scrollIntoView , 300 ) ; scrollTimer = setTimeout ( scrollIntoView , 1000 ) ; } ) ; input . addEventListener ( 'blur' , ( ) => { clearTimeout ( scrollTimer ) ; if ( scrollType && iOS ) { setTimeout ( ( ) => { document . body . scrollIntoView ( ) ; } ) ; } } ) ; }