Scrolling while navigation in the Same page?

Hello there,

Well I have come across this problem that in big lenghty pages I am creating, I want to place a link to Go to Top or Go here/there in the same page. IT is working absolutely fine with the Anchor tags.

The problem is It just shows me the portion I am linking directly, but I want it to scroll it, i.e, it should scroll to top and also for scroll for bottom instead of showing immediately/instantly. I guess some ScrollTo functionality of Jquery will work (as searched in google).

I am very new to javascript, jquery and Confluence, so can anyone please tell me how to integrate it so that automatically while doing same page navigation, it scrolls.

Regards.

2 answers

This widget could not be displayed.
David Simpson Community Champion Nov 08, 2011

Better than my last answer, try this as it works...

<script>AJS.toInit(function(){
    AJS.$('a[href^="#"]').click(function(e){
         AJS.$('html,body').animate({scrollTop: AJS.$( AJS.$(this).attr('href' )).offset().top});
        e.preventDefault();
    });
});</script>

Update: This works if added to the At the end of the HEAD section. I forgot to add AJS.$ to the jQuery object :(

I added this:

<script type="text/javascript">
AJS.toInit(function(){
	$('a[href^="#"]').click(function(e){
		 $('html,body').animate({scrollTop: $( $(this).attr('href' )).offset().top});
		e.preventDefault();
	});
});
</script>

in my Administrator -> Custom HTML -> At end of the HEAD but still it is not scrolling!

David Simpson Community Champion Nov 08, 2011

Good call. check the update above.

Added the NEW code At the end of the HEAD section. Now whats happening is, when I go to the link, and click on it, nothing is happening. should I add something more to the head section?

EDIT: It is working with Global Look and Feel theme but I am using Documentation theme.

This widget could not be displayed.
David Simpson Community Champion Nov 08, 2011

Try this:

http://djpate.com/2009/10/07/animated-scroll-to-anchorid-function-with-jquery/

By the way: Atlassian refers to their version of jQuery with AJS.$ instead of jQuery or $.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

305 views 2 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you