Steve
Steve

Reputation: 8293

Scroll to element on different page

Is it possible to scroll to an element on another page.

I have contact details at the bottom of xyz page and a contact button on the about us page. Once the user clicks the contact button on the about us page i would like them to go to xyz page and then automatically scroll to contact details at bottom.

$("#contact-btn").click(function (){
            //$(this).animate(function(){
                $('html, body').animate({
                    scrollTop: $("#contact").offset().top
                }, 1000);
            //});
        });

Upvotes: 1

Views: 188

Answers (1)

Axel
Axel

Reputation: 3323

Sure you can...

Let's say you have a link on "index.htm": <a href="contact.htm#bottom">Contact</a>.

And on site "contact.htm" you have a tag: <div id="bottom"></div>.

So if the browser loads the new site with hash "http://yoursite.com/contact.htm#bottom" it will "jump" to the bottom of the page automatically - but this will not look like a scroll event!

If you want to have a nice scroll effect you must not have an anchor with id equals hash but read the hash with javascript document.location.hash analyze it and scroll like you are used to scroll if the user is on the same site the scroll event takes place.

best regards :)

Upvotes: 2

Related Questions