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

1 vote
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.

0 vote
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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

872 views 23 12
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