7

脚本id为块添加,给出:

<div id="some">Text</div>

在该页面应该跳转id之后,没有动画,就像我们#some在当前页面链接上有目标一样。

这该怎么做?

谢谢。

4

4 回答 4

24

试试这个:

 document.getElementById('some').scrollIntoView(true);
于 2010-06-11T14:38:14.653 回答
13

你的意思是像#some这样链接“老派”吗

例如

<a href="#some"></a>

在 JS 中完成

location.href = "#some"; 
于 2010-06-11T14:39:13.013 回答
5

像这样:

location.href = "#some"; 
于 2010-06-11T14:34:55.397 回答
3
$('a[href^="#"]').click(function() {
$('html,body').animate({ scrollTop: $(this.hash).offset().top});
return false;
e.preventDefault();
});
于 2014-04-07T11:12:46.417 回答