打开键盘时,iOS iPad固定位置断开 [英] iOS iPad Fixed position breaks when keyboard is opened

查看:110
本文介绍了打开键盘时,iOS iPad固定位置断开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击搜索表单"文本框字段时,标题的固定位置中断.它只是从页面顶部分离(固定在那里),并在虚拟键盘打开时开始在页面中间浮动.

Fixed position breaks on header when I click on the "Search Form" text box field. It simply detaches from the top of the page (as it's fixed up there) and starts floating middle of the page when the virtual keyboard opens up.

正常:

损坏:

推荐答案

我真的很喜欢这种解决方案( http://dansajin.com/2012/12/07/fix-position-fixed/).我将其打包到一个小jQuery插件中,因此我可以:

I really like this solution (http://dansajin.com/2012/12/07/fix-position-fixed/). I packaged it up into a little jQuery plugin so I could:

  • 设置哪个家长可以上课
  • 设置适用于哪些元素(不要忘记"textarea"和"select").
  • 设置父类名称是什么
  • 允许它被链接
  • 允许它多次使用

代码示例:

$.fn.mobileFix = function (options) {
    var $parent = $(this),

    $(document)
    .on('focus', options.inputElements, function(e) {
        $parent.addClass(options.addClass);
    })
    .on('blur', options.inputElements, function(e) {
        $parent.removeClass(options.addClass);

        // Fix for some scenarios where you need to start scrolling
        setTimeout(function() {
            $(document).scrollTop($(document).scrollTop())
        }, 1);
    });

    return this; // Allowing chaining
};

// Only on touch devices
if (Modernizr.touch) {
    $("body").mobileFix({ // Pass parent to apply to
        inputElements: "input,textarea,select", // Pass activation child elements
        addClass: "fixfixed" // Pass class name
    });
}

已删除不必要的元素

这篇关于打开键盘时,iOS iPad固定位置断开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆