iphone设备输入时,自动定位到输入框

This commit is contained in:
Tim 2016-08-25 14:30:42 +08:00
parent ae09d7ff27
commit 78123b5db7
1 changed files with 17 additions and 13 deletions

View File

@ -1,17 +1,20 @@
/** /**
* Created by ttang on 2016/8/22. * Created by ttang on 2016/8/22.
*/ */
app.directive('iphoneRecognize',function(){ app.directive('iphoneRecognize',["$timeout",function(timer){
return{ return{
restrict: 'A', restrict: 'A',
scope: {}, scope: {},
link: function(scope, element){ link: function(scope, element){
timer(function(){
var userAgent = navigator.userAgent; var userAgent = navigator.userAgent;
var contentHeight = $(".post-container").height();
if (/ipad|iphone|mac/i.test(navigator.userAgent)){ if (/ipad|iphone|mac/i.test(navigator.userAgent)){
$("#postInput1").bind('focus',function(){ $("#postInput1").bind('focus',function(){
element.css({"position":"relative","padding":"1px 0"}); element.css({"position":"relative","padding":"1px 0"});
$(".post-wrapper").css("margin-bottom","0"); $(".post-wrapper").css("margin-bottom","0");
$("#all_homework_reply").css("margin-bottom","0"); $("#all_homework_reply").css("margin-bottom","0");
window.scrollTo(0,contentHeight);
}); });
$("#postInput1").bind('blur',function(){ $("#postInput1").bind('blur',function(){
element.css("position","fixed"); element.css("position","fixed");
@ -19,6 +22,7 @@ app.directive('iphoneRecognize',function(){
$("#all_homework_reply").css("margin-bottom","50px"); $("#all_homework_reply").css("margin-bottom","50px");
}); });
} }
})
} }
} }
}); }]);