javascript - 单击确定后如何停止 sweetalert 滚动到顶部?

标签 javascript jquery html sweetalert2

我正在使用 sweetalert2当用户在我的网站上发表评论时的脚本,它向下滚动到他们的评论并弹出甜蜜警报,但当他们在甜蜜警报框上单击“确定”时,它会滚动回顶部。

根据我一直在阅读的内容,我需要某种防止默认或其他东西,但我无法弄清楚它会去哪里?

这是我的脚本:

<!-- Sweet alert -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.8/sweetalert2.min.js"></script>
<script>
window.location.hash = "comment-<?php echo $newcommentid; ?>";
 $(document).ready(function () {
    swal({
                title: "Comment Posted",
                text: "Thanks, your comment has now been successfully posted.",
                type: "success"
            });
 });     

</script>

最佳答案

我通过简单地在 fire(): heightAuto: false

中添加一行成功地阻止了这种情况
Swal.fire({
  heightAuto: false,
  text: "I\'m sure this would run on SWAL2@7*"
)};

关于javascript - 单击确定后如何停止 sweetalert 滚动到顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46135063/

相关文章:

javascript - 如何将事件监听器附加到 GETElementsByClassName()

javascript - 双击元素时循环遍历 jQuery 中的元素

javascript - 如何在 php laravel 的第二页保留过滤器选项?

javascript - 正则表达式 - 用一个替换多个 html 标签

html - 使用精确的百分比和字体大小 :0 to make grids that fit perfectly?

javascript - 任何文本输入更改时运行函数

javascript - 如何以编程方式使用 certbot 启用/禁用 SSL

javascript - "Thinking in AngularJS"如果我有 jQuery 背景?

javascript - 防止用户发送空字段

jquery - 如何使用hexo弹出图片