Javascript 原生效果JS动态滑动切换到页面指定位置

发布于:2021-10-22 17:55:13

方法一:window.scroll

将页面动态划到指定的位置。

浏览器:IE11以上

window.scroll({
  top: 2500, 
  left: 0, 
  behavior: 'smooth' 
});
// Scroll certain amounts from current position 
window.scrollBy({ 
  top: 100, // could be negative value
  left: 0, 
  behavior: 'smooth' 
});

方法二:element.scrollIntoView

浏览器:IE11

划到指定的元素的位置。

// Scroll to a certain element
document.querySelector().scrollIntoView({ 
  behavior:  
});

方法二:jQuery

划到指定的锚点位置,兼容所有浏览器

//   links  hashes
$()
  // Remove links that don
[href=]
[href=]









[=]




html, 









tabindex

http://ourjs.com/detail/5b11ff821fba5269ce0530c5

阅读 213+

一片空白

父爱如山,不善表达。回想十多年前,总记得父亲有个宽厚的肩膀,小小的自己跨坐在上面,越过人山人海去看更广阔的天空,那个时候期望自己有一双翅膀,能够像鸟儿一样飞得高,看得远。虽然父亲有时会和自己开玩笑,但在做错事的时候会受到严厉的训斥。父亲有双粗糙的大手掌。