Last active
August 29, 2015 14:18
-
-
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)
This file contains 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
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); | |
} | |
}); | |
} |
This file contains 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
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