2 $.fn.autoscroll = function(synchronizeWith, options) {
4 var selfContainer = self.parent();
5 var synchronizeWith = $(synchronizeWith);
6 var synchronizeWithContainer = synchronizeWith.parent();
7 var eventContainer = synchronizeWithContainer;
10 if (self.is('iframe')) {
11 selfContainer = $('body', $('iframe').contents());
15 if (synchronizeWith.is('iframe')) {
16 eventContainer = synchronizeWith.contents();
17 synchronizeWithContainer = $('body', eventContainer);
18 synchronizeWith = synchronizeWithContainer;
21 synchronizeWithContainer.data('autoscroll.lastCheckedScrollTop', synchronizeWithContainer.scrollTop());
23 eventContainer.scroll(function() {
24 var distanceScrolled = synchronizeWithContainer.scrollTop() - synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop');
25 var percentScrolled = distanceScrolled / synchronizeWith.height();
26 selfContainer.scrollTop(selfContainer.scrollTop() + percentScrolled * self.height());
27 synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop', synchronizeWithContainer.scrollTop());