One: Scroll through the HTML anchor point to the page specified location (DIV):
If we want to click on the implementation of the jump is an HTML anchor point, that is, click on a tag hyperlink to achieve a jump, you can put the href attribute of a tag directly to jump to the specified position of the Div, the code implementation ideas are as follows:
<a class= "banner" href= "/schoolfair/registration#nav" >
<a href= "#abc" > click to jump </a>
<div id= "ABC" > is going to jump here </div>
Second: Use JS to scroll to the page specified location (DIV) by clicking the button buttons:
If we want to click on the implementation of the jump to the place is a button, because the button can not add href, so we have to use the JS jump code to implement, the specific code example is as follows:
<script>
function Ontopclick () {
Window.location.hash = "#abc";
}
</script>
<input type= "button" name= "Submit" value= "commit" onclick= "Javascript:ontopclick ();"/>
<div id= "abc" > Jump to the location </div>
The above code, click the Submit button, will scroll to navigate to the same page id= "abc" Div. This JS click Jump page Code implementation of the principle is: the page each element to give a unique ID, click the Submit button to trigger the JS Click event, JS through the ID scrolling jump to navigate to the element, Window.location.hash = "#abc" refers to the location of the current page id= "ABC" The Div.
Window.location.href: Redirect, followed by the full URL address, and similar to the Window.location.hash,
Here's a comparison between Window.location.href and Window.locaiton.hash.
(1) window.location.href
Get and use the complete URL, such as window.location.href= "www.baidu.com" means redirect, page jump
to the new page. You can also get the full href of a tag by window.location.href, such as <a href= "#book" > If you use href, then
You can get the full link (URL)
(2) Window.location.hash
Get the anchor chain connection. Compared to the href, through Window.location.hash does not jump to the new link, only in the current link inside
Change the anchor chain. And if there is <a href= "#book" > through Window.location.hash not get the complete link (URL), just get #book.
HTML JS Click the button to scroll to navigate to the page to specify the location (DIV) of the method code