`
sailei1
  • 浏览: 124639 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Sencha Touch TextArea 支持滑动

阅读更多
TextArea ios 支持滑动


Ext.define('Sai.view.TextArea', {
    extend: 'Ext.form.TextArea',
    xtype:'scrollTextArea',
   initialize: function() {
      this.callParent();
      this.element.dom.addEventListener(
         Ext.feature.has.Touch ? 'touchstart' : 'mousedown',
         this.handleTouchListener = Ext.bind(this.handleTouch, this),
         false);
      this.element.dom.addEventListener(
         Ext.feature.has.Touch ? 'touchmove' : 'mousemove',
         this.handleMoveListener = Ext.bind(this.handleMove, this),
         false);
      this.moveListenersAttached = true;
   },
   destroy: function() {
         if (this.moveListenersAttached) {
         this.moveListenersAttached = false;
         this.element.dom.removeEventListener(
            Ext.feature.has.Touch ? 'touchstart' : 'mousedown',
            this.handleTouchListener,
            false);
         this.element.dom.removeEventListener(
            Ext.feature.has.Touch ? 'touchmove' : 'mousemove',
            this.handleMoveListener,
            false);
         this.handleTouchListener = this.handleMoveListener = null;
      };
      this.callParent();
   },
   handleTouch: function(e) {
      this.lastY = e.pageY;
   },
      handleMove: function(e) {
          var textArea = e.target;
          var top = textArea.scrollTop <= 0;
          var bottom = textArea.scrollTop + textArea.clientHeight >= textArea.scrollHeight;
          var up = e.pageY > this.lastY;
          var down = e.pageY < this.lastY;
          this.lastY = e.pageY;
     
          if((top && up) || (bottom && down))    e.preventDefault();
      
          if(!(top && bottom))    e.stopPropagation();
      }
});

1
0
分享到:
评论
1 楼 amwlgywxf 2013-05-17  
很有用,太厉害了,顶一个

相关推荐

Global site tag (gtag.js) - Google Analytics