小编mka*_*mid的帖子

ScrollIntoView 打破了溢出滚动

我有一个嵌套的子容器,当我尝试它时,scrollIntoView它会破坏父容器。我无法理解为什么它会这样。请帮我解决这个问题。
请查看下面的代码或jsfiddle上的代码

function moveToTop() {
  console.log('MOVE TO TOP::');
  const child = document.getElementById('child');
  child.scrollIntoView({
    behavior: "smooth"
  });
}
Run Code Online (Sandbox Code Playgroud)
#parent {
  background-color: blue;
  padding: 10px;
  height: 500px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#scroller {
  overflow: auto;
  padding: 10px;
  background-color: red;
  flex-grow: 1;
}

#child {
  height: 10000px;
  background-color: green;
}

body {
  overflow: hidden;
  color: #fff;
  font-weight: bold;
}

button {
  position: fixed;
  bottom: 20px;
  width: 140px;
  left: 20%;
  right: 0;
}
Run Code Online (Sandbox Code Playgroud)
<div id="parent">
  PARENT
  <div id="something">Something</div> …
Run Code Online (Sandbox Code Playgroud)

html javascript css overflow

6
推荐指数
1
解决办法
4470
查看次数

Typescript 将两种数据类型数组合并为一个

如何使用concat. 如果我用两种数据类型初始化它,它工作得很好,但是当我concat这样做时。Typescript 会抛出两种类型不兼容的错误。

const foo: string[] = ['hello', 'world'];
const bar: number[] = [1, 2];
const both: (string | number)[] = foo.concat(bar); // gets an error on bar

const other: (string | number)[] = ['hello', 'world', 2, 3]; // this works
Run Code Online (Sandbox Code Playgroud)

javascript arrays types typescript

2
推荐指数
1
解决办法
3567
查看次数

标签 统计

javascript ×2

arrays ×1

css ×1

html ×1

overflow ×1

types ×1

typescript ×1