Skip to content

Instantly share code, notes, and snippets.

@CharlesAnifowose
Last active August 29, 2015 14:18
Show Gist options
  • Save CharlesAnifowose/7bdfe34646f00eeac504 to your computer and use it in GitHub Desktop.
Save CharlesAnifowose/7bdfe34646f00eeac504 to your computer and use it in GitHub Desktop.
synchronized scrolling of an arbitrary number of elements (this one is focused on y axis)
var scrollWatches = {};
var setupScrollWatch = function(id, _el){
if (!scrollWatches[id]){
scrollWatches[id] = [];
}
if (_.indexOf(scrollWatches[id], _el) == -1){
scrollWatches[id].push(_el);
$(_el).scroll(function(a,b){
syncToScroll(id, _el);
});
return true;
}
return false;
}
var syncToScroll = function(id, _el){
var scrollTop = _el.scrollTop();
_.each(scrollWatches[id], function(_el_pair){
if (-el != _el_pair){
_el_pair.scrollTop(scrollTop);
}
});
}
scope.syncToCfScroll = function(){
var id = 'cf-y';
_.each( el.find('.t-sync-to-cf-panel'), function(_el){
setupScrollWatch( id, $(_el) );
});
setTimeout(function(){
syncToScroll( id, $(elselect('curriculum_framework_list')) );
}, 20)
}
var setupCFScrollWatch = function(){
var _el = elselect('curriculum_framework_list');
setupScrollWatch('cf-y', _el);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment