以编程方式将Sencha Touch Ext.Panel滚动到锚元素

tcu*_*rdt 2 extjs sencha-touch

我有一个可滚动的面板,显示大于屏幕的内容

new Ext.Panel({
  scroll: 'vertical',
  html: 'very larger content here with an anchor. <p id="anchor">'
});
Run Code Online (Sandbox Code Playgroud)

和(在点击事件上)我想(以编程方式)将面板滚动到某个HTML元素.最好甚至是动画的.在jquery中,我会做一些事情

$('html,body').animate({ scrollTop: $("#anchor").offset().top }, 'slow');
Run Code Online (Sandbox Code Playgroud)

tcu*_*rdt 6

原来你可以做的是

function scrollIntoView(el,cmp) {
  var dy = cmp.scroller.offset.y + el.getY() - cmp.body.getY();
  cmp.scroller.setOffset({x:0, y:-dy}, true);
}

scrollIntoView(Ext.fly('anchor'), Ext.getCmp('panel'));
Run Code Online (Sandbox Code Playgroud)

这可能与scrollIntoView()内部的内容非常相似- 虽然没有看过那些代码.但它没有动画.

  • 这很棒.在Sencha 2中,该方法的第一行现在需要如下所示:cmp.getScrollable().getScroller().position.y + el.getY() - cmp.body.getY() (2认同)