Javascript 使用jquery平滑滚动到另一页上的ID Div
我有一个“link.html”页面,它有一个指向index.html页面的锚点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.
,我目前正在使用下面的脚本,该脚本经过修改,最初来自
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);
};
});