Php 页面加载后滚动至div smoothy,而不是直接滚动

Php 页面加载后滚动至div smoothy,而不是直接滚动,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我有一个php页面,我试图在整个页面加载后自动将用户滚动到该部分。现在直接转到页面加载部分,我希望加载整个页面,然后将页面滚动到该分区。我正在做的是 <script type="text/javascript"> <!-- function gotoit() { window.location="#gohere"; } //--> </script> <body onload="gotoit()"> some code here <a na

我有一个php页面,我试图在整个页面加载后自动将用户滚动到该部分。现在直接转到页面加载部分,我希望加载整个页面,然后将页面滚动到该分区。我正在做的是

<script type="text/javascript">
<!--
function gotoit()
{
window.location="#gohere";
}
//-->
</script>

<body onload="gotoit()">
some code here
<a name="gohere"><div class="I want to scroll to this div"></a>

这里有一些代码

请帮助我如何在页面加载后自动平滑地滚动到该部分。

以下是我用来实现此目的的jQuery函数:

function scrollToStart(){
$("#scrollToStart").click(function (){
       $('html, body').animate({
       scrollTop: $("#startHere").offset().top
     }, 2000);

});
};

下面是我用来实现这一点的jQuery函数:

function scrollToStart(){
$("#scrollToStart").click(function (){
       $('html, body').animate({
       scrollTop: $("#startHere").offset().top
     }, 2000);

});
};

$(窗口)。加载(函数(){
var theHash=“#转到这里”;
$(“html,body”).animate({scrollTop:$(theHash.offset().top},800);
});
这里有很多内容

更多内容

等等

自动向下滚动至此处

更多内容

$(window).load()确保页面在加载所有其他资产(例如图像)后开始滚动。


$(窗口)。加载(函数(){
var theHash=“#转到这里”;
$(“html,body”).animate({scrollTop:$(theHash.offset().top},800);
});
这里有很多内容

更多内容

等等

自动向下滚动至此处

更多内容


$(window).load()确保页面在加载所有其他资产(例如图像)后开始滚动。

代码应该在页眉中吗?我该怎么装尸体呢?就这样行吗?那代码应该在页眉里吗?我该怎么装尸体呢?就这样行吗?