sweetalert2 target opt - swal 仍然在目标之外
sweetaler2 target opt - swal still outside the target
我在 sweetalert2 中尝试了 target opt,但是 toast 仍然出现在 target 之外
我做错了什么?
这是代码
#trial {
position: absolute;
display: block;
height:200px;
width: 500px;
border: 1px solid;
}
<div id="trial"></div>
<script>
$(document).ready(function() {
var id = document.getElementById('trial');
Swal.fire({
title: 'I will be placed inside the #swal2-container',
toast: true,
target: id,
position: 'bottom-left'
});
});
</script>
这里是结果:
使用 target
属性,所发生的只是 DOM 容器 .swal2-container
附加到目标元素,但它具有 position: fixed;
样式,您将需要按如下方式覆盖它:
$(document).ready(function() {
var id = document.getElementById('trial');
Swal.fire({
title: 'I will be placed inside the #swal2-container',
toast: true,
target: id,
position: 'bottom-left'
});
});
#trial {
position: relative;
left: 50px;
display: block;
height: 200px;
width: 500px;
border: 1px solid;
}
.swal2-container{
position: absolute !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<div id="trial"></div>
我在 sweetalert2 中尝试了 target opt,但是 toast 仍然出现在 target 之外
我做错了什么?
这是代码
#trial {
position: absolute;
display: block;
height:200px;
width: 500px;
border: 1px solid;
}
<div id="trial"></div>
<script>
$(document).ready(function() {
var id = document.getElementById('trial');
Swal.fire({
title: 'I will be placed inside the #swal2-container',
toast: true,
target: id,
position: 'bottom-left'
});
});
</script>
这里是结果:
使用 target
属性,所发生的只是 DOM 容器 .swal2-container
附加到目标元素,但它具有 position: fixed;
样式,您将需要按如下方式覆盖它:
$(document).ready(function() {
var id = document.getElementById('trial');
Swal.fire({
title: 'I will be placed inside the #swal2-container',
toast: true,
target: id,
position: 'bottom-left'
});
});
#trial {
position: relative;
left: 50px;
display: block;
height: 200px;
width: 500px;
border: 1px solid;
}
.swal2-container{
position: absolute !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<div id="trial"></div>