在参考站点(http://en.wikipedia.org/wiki/Dobroslav_Jevdevic)中,这是通过 id 的 hwlp 完成的。例如<a href="#abc">Click Here</a>
,在锚标签href中,我们传递了点击锚标签时页面应该滚动的元素的id。但是为了提供平滑的效果,你必须使用jquery方法。还有你可以使用的javascript方法scrollTo()方法。如果您只想将 html 代码用于相同目的而不是 jquery,然后查看此代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<a href="#abc">Click Here</a>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<h2 id="abc">Main Section</h2>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
</body>
</html>