首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >div中的SweetAlert2

div中的SweetAlert2
EN

Stack Overflow用户
提问于 2020-11-09 07:54:34
回答 1查看 375关注 0票数 2

我遇到了同样的问题,我希望在一个div中有sweetalert2 (而不是一个甜蜜警报吐司),因为我希望当甜蜜警报弹出时,除了它之外的另一个div是可滚动的。我已经尝试了上面的代码,但它仍然不能工作。请看这里的图片:sweetalert2

代码语言:javascript
复制
var id = document.getElementById('mydiv');
swal({
title: "question",
target: id,
showConfirmButton: false,
showCloseButton: true,
allowOutsideClick: false,
allowEscapeKey : false,
customClass: "swal-height"
});

我也有固定的位置在css

代码语言:javascript
复制
#mydiv{
  overflow: hidden;
  height: calc(100% - 300px) !important;
  padding-bottom: 70px;
  position: relative !important;
}

#mydiv .swal-height {
    position:absolute !important;
    height: 720px !important;
    width: 780px !important;
    margin-left: 1100px !important;
    margin-top: 280px !important;
}

你能建议我哪里做错了吗?

下面是与我正在构建的JSFiddle类似的代码:https://jsfiddle.net/0pt2vr87/7/

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-10 04:20:35

您错误地使用了customClass参数,它应该是一个对象,而不是字符串。

代码语言:javascript
复制
Swal.fire({
  text: 'Modal inside a custom target',
  target: '#custom-target',
  customClass: {                      // <------ customClass is an object!
    container: 'position-absolute'
  },
})
代码语言:javascript
复制
#custom-target {
  position: relative;
  width: 300px;
  height: 200px;
  border-style: solid;
}

.position-absolute {
  position: absolute !important;
}
代码语言:javascript
复制
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> 

<div id="custom-target"></div>

查看官方示例:https://sweetalert2.github.io/recipe-gallery/toast-with-custom-target.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64744259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档