为了账号安全,请及时绑定邮箱和手机立即绑定

div 内的 SweetAlert2

div 内的 SweetAlert2

慕森卡 2023-07-20 16:06:10
我遇到了同样的问题,我希望在 div 中包含 sweetalert2 (不是 sweetalert toast),因为我希望除它之外的另一个 div 在弹出 sweetalert 时可以滚动。我已经尝试过上面的代码,但它仍然无法正常工作。var id = document.getElementById('mydiv');swal({title: "question",target: id,showConfirmButton: false,showCloseButton: true,allowOutsideClick: false,allowEscapeKey : false,customClass: "swal-height"});我也有固定的CSS定位#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/感谢您的帮助。
查看完整描述

1 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

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


Swal.fire({

  text: 'Modal inside a custom target',

  target: '#custom-target',

  customClass: {                      // <------ customClass is an object!

    container: 'position-absolute'

  },

})

#custom-target {

  position: relative;

  width: 300px;

  height: 200px;

  border-style: solid;

}


.position-absolute {

  position: absolute !important;

}

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> 


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

查看完整回答
反对 回复 2023-07-20
  • 1 回答
  • 0 关注
  • 87 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信