Load page and scroll automatically to a certain element

2

In a contact page there is in order: a banner, map and form.

How can I make the page automatically scroll down by letting the page start automatically from the map?

    
asked by anonymous 27.08.2015 / 14:31

4 answers

7

In the header, <head></head> , add the following code between the <script></script> tag:

$(document).ready(function() { 
window.location.href='#foo';
});

The ready() method indicates that the script within the function will run only when the page is ready with all elements loaded.

This way, you do not need to put the script at the bottom of the page, as well as being more secure.

Where you want the page to stop scrolling, place:

<a href="#" id="foo"></a>
    
27.08.2015 / 23:52
1

An example would be window.scrollTo(0, 10); as I do not know anything about your source code, what gives p / answer would be that.

    
27.08.2015 / 15:18
1

You can use the page ID itself as a reference to use as anchor Example: But # is needed in javaScript         window.location.href = '#DataPage';

    
06.03.2017 / 17:59
0

You can use an anchor:

place this code at the end of your page

<script>
window.location.href='#ancora';
</script>

and now put a <a href="#" id="ancora"> field below the div or html element.

    
27.08.2015 / 23:13