2 $.fn.autoscroll = function(synchronizeWith, options) {
5 var selfContainer = self.parent();
6 var synchronizeWith = $(synchronizeWith);
7 var synchronizeWithContainer = synchronizeWith.parent();
8 var eventContainer = synchronizeWithContainer;
11 if (self.is('iframe')) {
12 selfContainer = $('body', $('iframe').contents());
16 if (synchronizeWith.is('iframe')) {
17 eventContainer = synchronizeWith.contents();
18 synchronizeWithContainer = $('body', eventContainer);
19 synchronizeWith = synchronizeWithContainer;
22 $this.data('autoscroll:enabled', true);
23 synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop', synchronizeWithContainer.scrollTop());
25 eventContainer.scroll(function() {
26 if ($this.data('autoscroll:enabled')) {
27 var distanceScrolled = synchronizeWithContainer.scrollTop() - synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop');
28 var percentScrolled = distanceScrolled / synchronizeWith.height();
29 selfContainer.scrollTop(selfContainer.scrollTop() + percentScrolled * self.height());
31 synchronizeWithContainer.data('autoscroll:lastCheckedScrollTop', synchronizeWithContainer.scrollTop());
35 $.fn.enableAutoscroll = function() {
36 $(this).data('autoscroll:enabled', true);
39 $.fn.disableAutoscroll = function() {
40 $(this).data('autoscroll:enabled', false);
43 $.fn.toggleAutoscroll = function() {
44 $(this).data('autoscroll:enabled', !$(this).data('autoscroll:enabled'));