Skip to content

Commit

Permalink
Make cluster calculation work when clustered content is further down
Browse files Browse the repository at this point in the history
Let's say you have a page that is scrollable, with a screen or two (or more) of non-clustered content, followed by a massive list that you want to be clusterized (but not scrollable itself). This makes that work, by taking into account the offsetTop of the clustered content within the scrollable container, so that the correct cluster number is used.

I had this problem with my website, and found the solution in pull request NeXTs#103 (thanks @vsesh for figuring it out). This version is based on the latest version of the library and has been simplified to only modify one line. Works like a charm on my site. 

Note, no minified version in this pull request.
  • Loading branch information
banjerluke authored Aug 10, 2018
1 parent 74e8f10 commit 7e3e7f6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clusterize.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
},
// get current cluster number
getClusterNum: function () {
this.options.scroll_top = this.scroll_elem.scrollTop;
this.options.scroll_top = this.scroll_elem.scrollTop - this.content_elem.offsetTop;
return Math.floor(this.options.scroll_top / (this.options.cluster_height - this.options.block_height)) || 0;
},
// generate empty row if no data provided
Expand Down Expand Up @@ -328,4 +328,4 @@
}

return Clusterize;
}));
}));

0 comments on commit 7e3e7f6

Please sign in to comment.