PDA

View Full Version : jQuery Show element scrolls the page to the top: Solved


mberkom
03-31-2009, 05:37 PM
This problem solved

Okay I have another question.

In my code, using the "ajax" call I load an html div into my page, define its top and left and then make it visible using ".fadeIn()" (".show()" does the same thing). The element is positioned fixed and I want it (no matter where I am scrolled on the page) to show up the distance from the top and left that I specify. Instead it scrolls me to the top of the page before showing the element. How can I stop this scrolling and have it just show where I am scrolled on the page?



//".floating_box" refers to the div in the html
$.post(html_url, function(data){
$('body:last-child').append(data);
add_functionality();
});
$('.floating_box').css({'top' : '40px', 'left' : '400px'});
$('.floating_box').fadeIn('fast');

Eldarrion
03-31-2009, 05:52 PM
Doesn't seem to achieve that effect when tested locally. Where is the rest of your code? Perhaps something else is doing it... like a refresh or something else along those lines?

mberkom
03-31-2009, 06:51 PM
Alright, here is all my code. Problem occurs at line #103 in the scripts.js file. Thanks for the help.

Code removed

Eldarrion
03-31-2009, 07:14 PM
And the jumpy effect comes from:


<a href="#" class="activate_link">Activate Box Load</a><br />


I would suggest doing the following instead:


<a href="#" onclick='return false;' class="activate_link">Activate Box Load</a><br />


Which should force the browser to NOT follow the link and thus jump all the way up to the start of the page.

mberkom
03-31-2009, 07:21 PM
That was easy! I should have thought that it was the link reloading the page. Thanks for the help.