【问题标题】:$mdToast show/hide causes screen to scroll to top of website when overflow-y is set - AngularJS$mdToast 显示/隐藏在设置溢出-y 时导致屏幕滚动到网站顶部 - AngularJS
【发布时间】:2016-07-12 20:57:00
【问题描述】:

当用户提交表单时,我有一个简单的祝酒词

$mdToast.show(
    $mdToast.simple()
    .textContent('Your order form has been submitted.')
    .position('bottom left')
    .hideDelay(5000)
);

它起作用了,吐司出现在左下角,用户可以在网站可见时向下滚动。当它显示/隐藏时,它不会将视图滚动到屏幕顶部。但是我遇到了一个错误,吐司导致屏幕跳跃,因为它隐藏了垂直滚动条,然后又重新出现。

为了解决这个问题,我添加了

html {
    overflow-y:scroll;
}

这阻止了屏幕跳跃,但现在当 toast 显示/隐藏时,它会将屏幕滚动到页面顶部。

如何阻止它在显示/隐藏时滚动?

【问题讨论】:

    标签: css angularjs


    【解决方案1】:

    我遇到了同样的问题,

    我是这样解决的:

    在body中添加一个专用的div:

    <div id="toast-container"></div>
    

    使用这个 CSS:

      #toast-container
        position fixed
        top 0
        right 0
        left 0
        bottom 0
        visibility hidden
        > *
          visibility visible
    

    然后,只需在调用中添加父级:

      $mdToast.show({
        // ....
        parent: document.getElementById('toast-container')
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2014-05-10
      • 2015-04-04
      • 1970-01-01
      • 2022-09-23
      • 2013-06-22
      相关资源
      最近更新 更多