Skip to content

Commit 7e3e7f6

Browse files
authored
Make cluster calculation work when clustered content is further down
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.
1 parent 74e8f10 commit 7e3e7f6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clusterize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
},
196196
// get current cluster number
197197
getClusterNum: function () {
198-
this.options.scroll_top = this.scroll_elem.scrollTop;
198+
this.options.scroll_top = this.scroll_elem.scrollTop - this.content_elem.offsetTop;
199199
return Math.floor(this.options.scroll_top / (this.options.cluster_height - this.options.block_height)) || 0;
200200
},
201201
// generate empty row if no data provided
@@ -328,4 +328,4 @@
328328
}
329329

330330
return Clusterize;
331-
}));
331+
}));

0 commit comments

Comments
 (0)