我试图在hideDiv运行后调用closeModal,所以有时间看到div被隐藏了,但我正在寻找除setTimeout之外的另一种方式:
function hideDiv () {
$('.div').hide();
}
function closeModal() {
if($('.div').lenght === 0) {
$.modal.close();
}}
$('.button').on('click', () => {
hideDiv();
setTimeout(function(){ closeModal() }, 1000);
});
function hideDiv () {
$('.div').hide();
}
function closeModal() {
if($('.div').lenght === 0) {
$.modal.close();
}}
$('.button').on('click',aync () => {
await hideDiv();
closeModal() ;
});
给这个镜头
jQuery hide函数具有回调
用法
function hideDiv(callback) {
return $('.div').hide(400, callback);
}
function closeModal() {
if ($('.div').lenght === 0) {
$.modal.close();
}
}
$('.button').on('click', () => {
hideDiv(closeModal);
});
.div {
background: blue;
width: 50px;
height: 50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="div"></div>
<button class="button" type="button">Hide</div>