我有一个嵌套的子容器,当我尝试它时,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)如何使用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)