From 7535ba0cf28bf41623979796a145dd9efff12c02 Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Mon, 28 Oct 2013 18:00:26 -0700 Subject: [PATCH] scrollToRow --- .../polymer-virtual-list.html | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/list/elements/polymer-virtual-list/polymer-virtual-list.html b/list/elements/polymer-virtual-list/polymer-virtual-list.html index 5147abc..41e94ad 100644 --- a/list/elements/polymer-virtual-list/polymer-virtual-list.html +++ b/list/elements/polymer-virtual-list/polymer-virtual-list.html @@ -53,6 +53,7 @@ this.metrics = { scrollOffset: h ? 'scrollLeft' : 'scrollTop', offsetExtent: h ? 'offsetWidth' : 'offsetHeight', + offsetPosition: h ? 'offsetLeft' : 'offsetTop', extent: h ? 'width' : 'height', position: h ? 'left' : 'top' }; @@ -260,6 +261,25 @@ } } } + }, + setScrollOffsetImmediate: function(pos){ + this.scrollOffset = pos; + this.scroll(); + }, + scrollToRow: function(row) { + // find page and row in page + var pageNum = Math.floor(row / this.pageSize); + // guesstimate offset and scroll to it + var top = this.pageTops[pageNum] || this.calcPageTop(pageNum); + this.setScrollOffsetImmediate(top); + // re-scroll with updated info + var top = this.pageTops[pageNum]; + this.setScrollOffsetImmediate(top); + // scroll to offset on this page + var page = this.findPage(pageNum); + var rowInPage = row - pageNum * this.pageSize; + var rowOffset = page.children[rowInPage][this.metrics.offsetPosition]; + this.scrollOffset += rowOffset; } });