sencha touch之软键盘挡住输入框问题

sencha touch之软键盘挡住输入框问题
https://blog.csdn.net/weixin_43369058/article/details/86073929

Ext.define('ux.FieldScroller', {
	override: 'Ext.viewport.Default',
    onElementFocus: function() {
        this.callParent(arguments);
        
        this.scrollFocusedFieldIntoView();
    },
    
    scrollFocusedFieldIntoView: function() {
        var me = this,
            focusedDom = me.focusedElement,
            fieldEl = focusedDom && Ext.fly(focusedDom).up('.x-field'),
            fieldId = fieldEl && fieldEl.id,
            fieldCmp = fieldId && Ext.getCmp(fieldId),
            offsetTop = 0,
            scrollingContainer, scroller, scrollerEl, domCursor, thresholdY, containerHeight;
        if (!fieldCmp) {
            return;
        }
        
        scrollingContainer = fieldCmp.up('{getScrollable()}');
        if (scrollingContainer) {
            scroller = scrollingContainer.getScrollable().getScroller();
            scrollerEl = scroller.getElement();
            domCursor = focusedDom;
            
            while (domCursor && domCursor !== scrollerEl.dom) {
                offsetTop += domCursor.offsetTop;
                domCursor = domCursor.offsetParent;
            }
            
            containerHeight = scroller.getContainerSize().y;
            thresholdY = offsetTop + fieldEl.getHeight() + (me.config.fieldFocusPadding || 40);
            // console.log('offsetTop=%o, containerHeight=%o, thresholdY=%o', offsetTop, containerHeight, thresholdY);
            
            if (scroller.position.y + containerHeight < thresholdY) {
                // console.log('scrolling to ', thresholdY - containerHeight);
                scroller.scrollTo(0, thresholdY - containerHeight, true);
            }
        }
    }
}, 
	function() {
	    Ext.onSetup(function() {
	        Ext.Viewport.on('resize', 'scrollFocusedFieldIntoView');
	    });
	});

记得创建一个ux文件,和js文件夹是平级,在ux文件夹中创建FieldScroller.js文件,赋值上面代码,然后app.js或者app.json,看你的程序加载的是哪一个,然后在Ext.application里面添加requires : ‘ux.FieldScroller’。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值