移动端IOS 固定下方的输入框,点击输入框位置会变的修复
2017-02-24 17:01
267 查看
if(data=="ios"){ var _this = $(".publish"); //无键盘时输入框到浏览器窗口顶部距离 var noInputViewHeight = $(window).height() - $(_this).height(); //网页正文内容高度 var contentHeight = $(document).height() - $(_this).height(); //控制正文内容高度大于一屏,保证输入框固定底部 contentHeight = contentHeight > noInputViewHeight ? contentHeight : noInputViewHeight; $('#txt_question').focus(function(){ iosinput = 1; setTimeout(function(){ //弹出输入法时滚动条的起始滚动距离 var startScrollY = $(window).scrollTop(); //弹出输入法时输入框到窗口顶部的距离,即到软键盘顶部的起始距离 var inputTopHeight = $(_this).offset().top - startScrollY; //弹出输入法时输入框预期位置,即紧贴软键盘时的位置。因输入框此时处于居中状态,所以其到窗口顶部距离即为需往下移动的距离。 var inputTopPos = $(_this).offset().top + inputTopHeight; //控制div不超出正文范围 inputTopPos = inputTopPos > contentHeight ? contentHeight : inputTopPos; $(_this).css({'position':'absolute', 'top':inputTopPos}); $(_this).addClass("cate52"); //给窗口对象绑定滚动事件,保证页面滚动时div能吸附软键盘 $(window).bind('scroll', function(){ //表示此时有软键盘存在,输入框浮在页面上了 if (inputTopHeight != noInputViewHeight) { //页面滑动后,输入框需跟随移动的距离 var offset = $(this).scrollTop() - startScrollY; //输入框移动后位置 afterScrollTopPos = inputTopPos + offset; //设置输入框位置使其紧贴输入框 if(iosinput==1){ $(_this).css({'position':'absolute', 'top':afterScrollTopPos }); } } }); }, 1000); }) $('#txt_question').blur(function(){ iosinput = 0; //输入框失焦后还原初始状态 $(_this).removeAttr('style'); $(_this).removeClass("cate52"); $(window).unbind('scroll'); }) }
相关文章推荐
- 取消a标签在移动端点击时的背景颜色 && 去除ios手机端input输入框上方有阴影
- div+css中如何将层随着滚动条的移动的初始位置固定在导航栏左下方
- 使用js写点击一个事件使页面返回顶部以及控制一个元素在右下角的固定位置的方法
- iOS 大头针怎么固定在中间,且移动后及时更新位置信息
- iOS开发记录——点击输入框上移屏幕,点击空白处隐藏键盘
- iOS-UIButton-文字位置,字体大小,边角样式,button种类,点击事件,内容位置
- 在固定位置创建子窗口,点击父窗口自动隐藏子窗口
- iOS开发之解决隐藏tabbar后原位置无法响应点击事件的问题
- iOS TextField输入框点击键盘时随着键盘上移
- 手机端点击按钮阴影 ios输入框阴影解决方法
- iOS陆先森开发随笔(四)tablview点击push到下一个页面,pop出来时位置下移问题
- ios tableCell 中同时获取点击的位置和所在的indexPath
- IOS_加速计_碰撞检测_小球位置修复_dispatch_once单例
- android关于输入框弹出后 点击输入框以外的位置会让输入框消失
- iOS-设置-app-位置,点击位置奔溃的原因
- iOS UITextField位置随输入键盘动态改变 点击背景键盘消失
- qt实现点击输入框弹出输入面板和改变窗口的位置
- winform 点击按钮,弹出窗体,弹出窗体的位置在按钮的下方
- iOS 评论界面 监听键盘高度 动态改变输入框位置
- iOS:实现MKAnnotation协议,在地图上设置大头针,点击显示具体的位置信息