Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 7535ba0

Browse files
committed
scrollToRow
1 parent 06b40a3 commit 7535ba0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

list/elements/polymer-virtual-list/polymer-virtual-list.html

+20
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
this.metrics = {
5454
scrollOffset: h ? 'scrollLeft' : 'scrollTop',
5555
offsetExtent: h ? 'offsetWidth' : 'offsetHeight',
56+
offsetPosition: h ? 'offsetLeft' : 'offsetTop',
5657
extent: h ? 'width' : 'height',
5758
position: h ? 'left' : 'top'
5859
};
@@ -260,6 +261,25 @@
260261
}
261262
}
262263
}
264+
},
265+
setScrollOffsetImmediate: function(pos){
266+
this.scrollOffset = pos;
267+
this.scroll();
268+
},
269+
scrollToRow: function(row) {
270+
// find page and row in page
271+
var pageNum = Math.floor(row / this.pageSize);
272+
// guesstimate offset and scroll to it
273+
var top = this.pageTops[pageNum] || this.calcPageTop(pageNum);
274+
this.setScrollOffsetImmediate(top);
275+
// re-scroll with updated info
276+
var top = this.pageTops[pageNum];
277+
this.setScrollOffsetImmediate(top);
278+
// scroll to offset on this page
279+
var page = this.findPage(pageNum);
280+
var rowInPage = row - pageNum * this.pageSize;
281+
var rowOffset = page.children[rowInPage][this.metrics.offsetPosition];
282+
this.scrollOffset += rowOffset;
263283
}
264284
});
265285
</script>

0 commit comments

Comments
 (0)