Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用scrollIntoView提供偏移量_Javascript_Angular_Typescript_Ionic3 - Fatal编程技术网

Javascript 使用scrollIntoView提供偏移量

Javascript 使用scrollIntoView提供偏移量,javascript,angular,typescript,ionic3,Javascript,Angular,Typescript,Ionic3,我正在使用scrollIntoView()转到选定的输入。但是我把它设为top,所以我想给它一个偏移量 但这似乎不起作用我也检查了scrollTo方法,并这样做: this.keyboard.onKeyboardShow().subscribe(() => { console.log('document.activeElement!!!!', document.activeElement) // document.activeElement.scrollIntoView(t

我正在使用
scrollIntoView()
转到选定的输入。但是我把它设为top,所以我想给它一个偏移量

但这似乎不起作用我也检查了scrollTo方法,并这样做:

this.keyboard.onKeyboardShow().subscribe(() => {
    console.log('document.activeElement!!!!', document.activeElement)
    // document.activeElement.scrollIntoView(true);
    const top = document.activeElement.getBoundingClientRect().top + window.scrollY;
    console.log(top);
    window.scroll(0, top)
    window.scrollTo({
       top: top,
       behavior: 'smooth'
    });
    // document.activeElement.scrollTo(0, 10);
    window.scrollBy(-100, 0);
});

但这将不再滚动到该元素。谁能帮我设置一个偏移量到
scrollIntoView()

我不知道你到底想做什么。是否要滚动到元素上方或下方?@ChrisSandvik滚动到document.activeElement,并在上方设置偏移量<代码>document.activeElement.scrollIntoView(true)这是有效的,但是用这种方法我不能给出任何偏移量。当你使用
窗口时,它是滚动的。滚动到
?因为你正在使用的偏移量应该是负的,根本不滚动,控制台。log(顶部)记录我
436.5238037109375
我也尝试过这个。带有viewchild(content)的内容可能尝试设置
left:0
在滚动选项中我不知道你到底想做什么。是否要滚动到元素上方或下方?@ChrisSandvik滚动到document.activeElement,并在上方设置偏移量<代码>document.activeElement.scrollIntoView(true)这是有效的,但是用这种方法我不能给出任何偏移量。当你使用
窗口时,它是滚动的。滚动到
?因为您正在使用的偏移量可能为负,根本不滚动,并且控制台。日志(顶部)记录我
436.5238037109375
我也尝试了此操作。带有viewchild(内容)的内容可能尝试在scrollTo选项中设置
left:0