Last active
August 29, 2015 14:02
-
-
Save buger/7f97dff2b44615930c54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderList(list) { | |
var $list = $(list); | |
var $container = $list.parent(); | |
var $items = $list.find('.list-item'); | |
var count = $container.height() / 68; | |
var offset = $container.scrollTop() / 68; | |
$items.each(function(idx, el){ | |
if (el.style.webkitTransform) { | |
var idx = parseInt(el.style.webkitTransform.match(/translateY\((\d+)px\)/)[1]) / 68; | |
if (idx >= (offset-1) && idx <= (count+offset+1)) { | |
el.style.display = 'block'; | |
} else { | |
el.style.display = 'none'; | |
} | |
} | |
}) | |
} | |
var _renderList = _.throttle(renderList, 200); | |
$('.instance-list').each(function(idx, el){ | |
_renderList(el); | |
var renderInterval; | |
var repaintNeeded = true; | |
$(el).parent().off('scroll'); | |
$(el).parent().on('scroll', function(evt){ | |
if (repaintNeeded) { | |
$(evt.target.children[0]).find('.list-item').each(function(idx,el){ | |
el.style.display = 'block'; | |
}) | |
repaintNeeded = false; | |
} | |
clearInterval(renderInterval); | |
renderInterval = setInterval(function(){ | |
_renderList(evt.target.children[0]); | |
repaintNeeded = true; | |
}, 500) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment