1 回答
TA贡献1848条经验 获得超10个赞
IE不支持ScrollBehavior
尝试这个
function scrollIntoWarranty() {
var el = document.querySelector("#tr_tab_2");
if ('scrollBehavior' in document.documentElement.style) { // behavior is not supported by IE
var offset = 50;
window.scroll({ top: (el.offsetTop - offset), left: 0, behavior: 'smooth' });
} else {
el.scrollIntoView();
}
}
<a href="#" onclick="scrollIntoWarranty(); return false;">
Go to warranty
</a>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
<div id="tr_tab_2">Warranty</div>
添加回答
举报