Hey all, I trying this unobtrusive JavaScript thing and I''ve run into a bit of an issue. I''m using the following code: Event.observe(window,''load'',function(){ new Effect.ScrollTo(''current'',{offest: -10}); return false; }); }); Now when I click ''current'' it performs the default action and just goes to the named anchor. It doesn''t perform the effect. It''s as if ''return false'' is not cancelling the default action. Is that how it''s done in Prototype? Thanks Iggy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Use Event.stop(event) and you''ll have to add the event argument to your function declaration. You say "when I click", but you are observing the window''s onload event so this should be happening without any clicks. FYI, offset is misspelled in case that is actually the code you use ;) Colin Iggy Sandejas wrote:> Hey all, > > I trying this unobtrusive JavaScript thing and I''ve run into a bit of an > issue. I''m using the following code: > > Event.observe(window,''load'',function(){ > new Effect.ScrollTo(''current'',{offest: -10}); > return false; > }); > }); > > Now when I click ''current'' it performs the default action and just goes > to the named anchor. It doesn''t perform the effect. It''s as if ''return > false'' is not cancelling the default action. Is that how it''s done in > Prototype? > > Thanks > Iggy > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Doh!! I actually forgot part of the code.. Complete Code is: Event.observe(window,''load'',function(){ Event.observe(''hardware-link'',''click'',function(){ new Effect.ScrollTo(''current'',{offset: -10}); return false; }); }) That should make more sense.. :) Iggy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Iggy, Iggy Sandejas a écrit :> Complete Code is: > Event.observe(window,''load'',function(){ > Event.observe(''hardware-link'',''click'',function(){ > new Effect.ScrollTo(''current'',{offset: -10}); > return false; > }); > })''K. So when you click on #hardware-link, you expect a ScrollTo effect over #current, is that right? This should cut it, BUT, your using "return false" is *not* the portable way of cancelling events. In Prototype, as you were told by a previous answer, you need to properly manipulate the event object for the current event. Your handler''s return value is of no account. Try this: Event.observe(window,''load'',function(){ Event.observe(''hardware-link'',''click'',function(e){ Event.stop(e); new Effect.ScrollTo(''current'', {offset: -10}); }); }) (Note the *e* argument to your handler) ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Cool thanks. I''ll try that and see how we go. Iggy On 2/23/07, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> > > Hey Iggy, > > Iggy Sandejas a écrit : > > Complete Code is: > > Event.observe(window,''load'',function(){ > > Event.observe(''hardware-link'',''click'',function(){ > > new Effect.ScrollTo(''current'',{offset: -10}); > > return false; > > }); > > }) > > ''K. So when you click on #hardware-link, you expect a ScrollTo effect > over #current, is that right? > > This should cut it, BUT, your using "return false" is *not* the portable > way of cancelling events. In Prototype, as you were told by a previous > answer, you need to properly manipulate the event object for the current > event. Your handler''s return value is of no account. > > Try this: > > Event.observe(window,''load'',function(){ > Event.observe(''hardware-link'',''click'',function(e){ > Event.stop(e); > new Effect.ScrollTo(''current'', {offset: -10}); > }); > }) > > (Note the *e* argument to your handler) > > ''HTH > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---