javascript - Focusing moved element ends up with half-focused element -
i'm developing application cordova/phonegap. on login page, form near bottom of screen. when user focuses element, i'm moving form top of screen otherwise ends underneath keyboard.
here's issue starts.
when using compiled apk on galaxy nexus (4.2.2) or visiting page directly 'browser' application, exhibits totally wacky behaviour.
after tapping form element, form moves up, keyboard pops up... , form element ends in weird half-focused state. i'm able type it, no cursor or selection outline displays, , hitting backspace not remove characters. other times can type , type into... somewhere, nothing displays in input box.
this same page works fine in safari on ios 7 , in chrome on desktop. page works fine in chrome on android.
markup:
<div class="form"> <input type="text" placeholder="focus me"> </div> css:
.form { position: absolute; bottom: 15%; left: 15%; width: 70%; } input { display: block; width: 100%; } javascript (with jquery 2.0.3):
$(".form input").focus(function() { $(".form").css({'bottom':'', 'top':'15%'}); }); $(".form input").blur(function() { $(".form").css({'bottom':'15%', 'top':''}); }); does have idea might causing this? known bug in older webkit builds? can suggest sensible workarounds? i've been banging head against way long.
thank you.
tried calling focus() on element after repositioning, tried doing after timeout (100-300 ms worked inconsistently). tried 50 other things.
i ended 'fixing' (i use term loosely) performing positioning after 1ms timeout. javascript ended up:
$(".form input").focus(function() { settimeout(function() { $(".form").css({'bottom':'', 'top':'15%'}); }, 1); }); $(".form input").blur(function() { settimeout(function() { $(".form").css({'bottom':'15%', 'top':''}); }, 1); }); all strange behaviour went away. should include caveat although have theories have no real idea @ why works. if knows of relevant bug against webkit or real explanation issue, i'm still interested in hearing it.
ymmv hth hand.
Comments
Post a Comment