Hi All,

I'm a fairly new prototype and scriptaculous user with limited
javascript experience.  I have been developing with Ruby on Rails for
some time, and found I needed to automatically scroll to the bottom of
a div as part of a series of animated effects.

Since Effect.ScrollTo only affects the whole document, I copied the
custom Effect.Scroll from http://pastie.org/36461, and modified it to
allow scrolling to the bottom of the element.  I have created an
extensions.js file and put the custom effect in there, and it runs
fine.

So here's my situation. I need users to be able to stop the scroll
either by clicking inside the element, or using their mousewheel on
it.  I've read a bunch of documents, including the tips and how-tos on
hooking events at proto-scripty.wikidot.com, and all seem to indicate
that something sort of like this is in order:

Event.observe(element, 'click', someFunctionThatStopsTheEffect)
Event.observe(element, 'mousewheel', someFunctionThatStopsTheEffect)

Questions:

1) Is 'mousewheel' a standard event?  If not, what is the correct way
to access mouse wheel behavior?
2) Can I embed these observers directly into the custom effect?  If
so, what is the proper location (initialize, setup, or update) where
they should reside?
3) If they can go into the custom effect, what's the proper way to
handle the function call?  Could I do something like this:
Event.observe(element, 'click', function() { this.cancel(); })
4) Or, is there some better way to do this entirely?

Thanks so much for any help you can offer.

Here is the code for my version of Effect.Scroll:

Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype,
Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      to_bottom: null,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }

    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;

    if (this.options.to_bottom) {
      this.options.y = this.element.scrollHeight;
    }

    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } else {

    }
  },
  update: function(position) {
    this.element.scrollLeft = this.options.x * position +
this.originalLeft;
    this.element.scrollTop  = this.options.y * position +
this.originalTop;
  }
});

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to