Question

Here my site: viettech-ca. com

My codes:

<div class="wrap footer-nav mgt35">
<ul>
<li><a href="bvct/chi-tiet/12/gioi-thieu.html">Về chúng tôi</a></li>
<li><a href="/bvct/chi-tiet/13/dai-ly.html">Đại lý</a></li>
<li><a href="/lienhe.html">Liên hệ</a></li>
<li><a href="/bvct/chi-tiet/14/dieu-khoan.html">Điều kiện &amp; Điều khoản</a></li>
<!--    <li><a href="--><!--">--><!--</a></li>--></ul>
<div><a class="go-top" href="#">Lên đầu trang</a></div>
</div>

go-top works, but it redirected me to the top of the homepage instead of the top of the current page.. Please show problem

Était-ce utile?

La solution

since you also have javascript:

JS:

function scroll2Top(){
    scroll(0,0);
}

HTML

<a class="go-top" onclick="scroll2Top();return false;">Lên đầu trang</a>

Autres conseils

I'm assuming you want to set up a 'Go to top' link in your page that takes the user back to the top of the page.

You do this with anchor tags where you would usually define it at the top of your code and then reference to it when required.

Code at top of html:

<body>
  <a name="top"></a>
  ...

Then your 'href' link would be as follows:

<div><a class="go-top" href="#top">Lên đầu trang</a></div>

If you leave out the top anchor name (name="top") it will still work, but this is bad practice because whats happening is that the page can't find the '#top' reference, it scrolls to the top anyway but because is can't find the link.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top