Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.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/7/css/32.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 当使用角度引导模式和窗口位置时,如何防止页面滚动到顶部:ipad的固定解决方法?_Javascript_Css_Angularjs_Twitter Bootstrap_Angular Bootstrap - Fatal编程技术网

Javascript 当使用角度引导模式和窗口位置时,如何防止页面滚动到顶部:ipad的固定解决方法?

Javascript 当使用角度引导模式和窗口位置时,如何防止页面滚动到顶部:ipad的固定解决方法?,javascript,css,angularjs,twitter-bootstrap,angular-bootstrap,Javascript,Css,Angularjs,Twitter Bootstrap,Angular Bootstrap,您可能知道,某些设备上的引导模式有一个bug,模式后面的页面会滚动,而不是模式() 通过添加css规则.modal open{position:fixed;},可以轻松修复此错误 但是这个修正产生了另一个bug——当你打开一个模式页面时,页面会滚动到顶部。可以通过JS解决,例如: 但我用的是软件包,它是。 因此,我不知道如何为show/hide事件上的所有Modal定义全局处理程序。我的代码中有太多模态,我不想在每个模态调用中定义这些处理程序,这太脏了 关于如何解决我的问题,有什么想法吗?请滚动

您可能知道,某些设备上的引导模式有一个bug,模式后面的页面会滚动,而不是模式()

通过添加css规则
.modal open{position:fixed;}
,可以轻松修复此错误

但是这个修正产生了另一个bug——当你打开一个模式页面时,页面会滚动到顶部。可以通过JS解决,例如:

但我用的是软件包,它是。 因此,我不知道如何为show/hide事件上的所有Modal定义全局处理程序。我的代码中有太多模态,我不想在每个模态调用中定义这些处理程序,这太脏了


关于如何解决我的问题,有什么想法吗?请滚动到最重要的问题?

也许你可以这样做。关闭功能在modal关闭时工作。这可以防止在模式关闭时页面向上滚动

ngOnInit(): void {
 document.body.style.position = 'initial';
 document.body.style.top = `-${window.scrollY}px`;
 ...
}

close(result?: any): void {
 this.activeModal.close(result || {});

 const scrollY = document.body.style.top;
 document.body.style.position = '';
 document.body.style.top = '';
 window.scrollTo(0, parseInt(scrollY || '0') * -1);
}

决定通过给所有模态体一个style
max height:calc(100vh-300px)来摆脱高模态自动溢出。这样所有的高模态都有可滚动的体