Re: Scriptaculous effects new help

Nathan Esquenazi
Mon, 31 Mar 2008 20:18:55 -0000

Well, fortunately, it is rather simple. Javascript is all about
listening to and binding to events. Right now in the code:

<a id="blink" style="cursor: pointer;" onclick =
"new
Effect.Highlight(''fun'', {duration:
2});">Flash

you are binding to the click event so that when the click event fires
you launch the highlight action.

You can just as easily bind to other events such as the page loading.
Currently, you are binding to the event inline meaning that the
"onclick" is being specified within the button.

I am an advocate of unobtrusive javascript when possible and you can
also bind to events through an unobtrusive method. That would be putting
the following in the application.js file in /public/javascripts:

$(''blink).observe(''click'', function() {
   new Effect.Highlight(''fun'', {duration: 2});
});

and then in the html:

Flash

Using this method, putting it on the page load is as simple as changing
the event being observed:


Event.observe(window, ''load'', function() {
   new Effect.Highlight(''fun'', {duration: 2});
});

--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---