Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery平滑滚动到另一页上的ID Div_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery平滑滚动到另一页上的ID Div

Javascript 使用jquery平滑滚动到另一页上的ID Div,javascript,jquery,html,Javascript,Jquery,Html,我有一个“link.html”页面,它有一个指向index.html页面的锚点,我目前正在使用下面的脚本,该脚本经过修改,最初来自 function doscorling(元素、持续时间){ 让bodyRect=document.body.getBoundingClientRect(), elementRect=element.getBoundingClientRect(), 偏移量=((elementRect.top-bodyRect.top)-40); 让startingY=window.

我有一个“link.html”页面,它有一个指向index.html页面的锚点
,我目前正在使用下面的脚本,该脚本经过修改,最初来自

function doscorling(元素、持续时间){
让bodyRect=document.body.getBoundingClientRect(),
elementRect=element.getBoundingClientRect(),
偏移量=((elementRect.top-bodyRect.top)-40);
让startingY=window.pageYOffset,
元素Y=偏移量,
目标,
差异,
easeInOutCubic,
开始
持续时间=持续时间| | 500;
//若元素靠近页面底部,那个么窗口将只滚动到元素上方的某个位置。。。
targetY=document.body.scrollHeight-elementY});
okay@LegenJerry,我正在进行更新。code ninja它不起作用它是纯javascript没有jqueryyeah,你为什么要在不需要jQuery的时候使用它?
 <a id="mylink" href="index.html?#myInnerLink">Go To MY InnerLink</a>
<div id="myDiv" class="mydiv">
SomeText here...
<div id="myInnerLink">
 ScrollTo This Div...
</div>
</div>
 $(document).ready(function() {
        if (window.location.hash) {
            var hash = window.location.hash;

            $('#myDiv').animate({
                scrollTop :  $(hash).offset().top
            }, 500);
        };
    });