virtualSearch(arr);
function virtualSearch(arr){
/**
* Creates a virtually-rendered scrollable list.
* @param {object} config
* @constructor
*/
function VirtualList(config) {
debugger
var width = (config && config.w + 'px') || '100%';
var height = (config && config.h + 'px') || '100%';
var itemHeight = this.itemHeight = config.itemHeight;
this.items = config.items;
this.generatorFn = config.generatorFn;
this.totalRows = config.totalRows || (config.items && config.items.length);
var scroller = VirtualList.createScroller(itemHeight * this.totalRows);
this.container = VirtualList.createContainer(width, height);
this.container.appendChild(scroller);
var screenItemsLen = Math.ceil(config.h / itemHeight);
// Cache 4 times the number of items that fit in the container viewport
this.cachedItemsLen = screenItemsLen * 3;
this._renderChunk(this.container, 0);
var self = this;
var lastRepaintY;
var maxBuffer = screenItemsLen * itemHeight;
var lastScrolled = 0;
// As soon as scrolling has stopped, this interval asynchronouslyremoves all
// the nodes that are not used anymore
this.rmNodeInterval = setInterval(function() {
if (Date.now() - lastScrolled > 100) {
var badNodes = document.querySelectorAll('[data-rm="1"]');
for (var i = 0, l = badNodes.length; i < l; i++) {
self.container.removeChild(badNodes[i]);
}
}
}, 300);
function onScroll(e) {
//debugger
e = e || window.event; //ie
var te = e.target || e.srcElement; //ie
var scrollTop = te.scrollTop; // Triggers reflow
if (!lastRepaintY || Math.abs(scrollTop - lastRepaintY) > maxBuffer) {
var first = parseInt(scrollTop / itemHeight) - screenItemsLen;
self._renderChunk(self.container, first < 0 ? 0 : first);
lastRepaintY = scrollTop;
}
lastScrolled = Date.now();
e.preventDefault && e.preventDefault();
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.