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

Commit

Permalink
scrollToRow
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Oct 29, 2013
1 parent 06b40a3 commit 7535ba0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions list/elements/polymer-virtual-list/polymer-virtual-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand Down Expand Up @@ -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;
}
});
</script>
Expand Down

0 comments on commit 7535ba0

Please sign in to comment.