I''ve been having this really annoying issue with any visual effect that I use in Rails. Say, for instance, that I have an Element.show or Element.hide link to expose a hidden div. Well, the effects work great, but if they are located far enough down on the page to necessitate scrolling, the effect makes the browser jump to the top of the page. This is basically the source output that is produced: <a href=''#'' onclick="Effect.toggle(''whatever'')">switch</a> <div id="whatever" style="display:none"> stuff goes here </div> Anyone run into this, know the cause and know how to stop it? -- Posted via http://www.ruby-forum.com/.
It''s the href="#" that''s making the page jump like that. You should put the onClick on a div or a span (anything but an anchor tag), and have some CSS to set a hover: icon change to simulate a link. Jason Ryan Williams wrote:> I''ve been having this really annoying issue with any visual effect that > I use in Rails. Say, for instance, that I have an Element.show or > Element.hide link to expose a hidden div. Well, the effects work great, > but if they are located far enough down on the page to necessitate > scrolling, the effect makes the browser jump to the top of the page. > > This is basically the source output that is produced: > > <a href=''#'' onclick="Effect.toggle(''whatever'')">switch</a> > > <div id="whatever" style="display:none"> > stuff goes here > </div> > > > Anyone run into this, know the cause and know how to stop it? > >
You can also try "Effect.toggle(''whatever''); return false;" which instructs the browser to cancel the navigation. On 6/20/06, Jason Roelofs <jameskilton@gmail.com> wrote:> It''s the href="#" that''s making the page jump like that. You should put > the onClick on a div or a span (anything but an anchor tag), and have > some CSS to set a hover: icon change to simulate a link. > > Jason > > Ryan Williams wrote: > > I''ve been having this really annoying issue with any visual effect that > > I use in Rails. Say, for instance, that I have an Element.show or > > Element.hide link to expose a hidden div. Well, the effects work great, > > but if they are located far enough down on the page to necessitate > > scrolling, the effect makes the browser jump to the top of the page. > > > > This is basically the source output that is produced: > > > > <a href=''#'' onclick="Effect.toggle(''whatever'')">switch</a> > > > > <div id="whatever" style="display:none"> > > stuff goes here > > </div> > > > > > > Anyone run into this, know the cause and know how to stop it? > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ryan Williams
2006-Jun-21 00:32 UTC
[Rails] Re: AJAX effects make browser jump to top of page
james payne wrote:> You can also try "Effect.toggle(''whatever''); return false;" which > instructs the browser to cancel the navigation.YES! Thank you. I actually just peaked at the 37 signals code and noticed they were doing that very thing. -- Posted via http://www.ruby-forum.com/.
Ryan Williams
2006-Jun-21 00:37 UTC
[Rails] Re: AJAX effects make browser jump to top of page
Jason Roelofs wrote:> It''s the href="#" that''s making the page jump like that. You should put > the onClick on a div or a span (anything but an anchor tag), and have > some CSS to set a hover: icon change to simulate a link.Thanks for the tip Jason. Yeah, I''ve been avoiding that since I''ve seen others get this working (not to mention it negates the whole link_to_remote method). The "return false;" did the trick. -- Posted via http://www.ruby-forum.com/.