我正在尝试创建一个弹出窗口,当用户执行操作时,该弹出窗口从屏幕的右下角滑入,停留几秒钟,然后滑出。我的代码有问题。这是我的JS:



function showModal() {
  $('#sideModal').css('display', 'block').animate({
    width: '20%',
    display: 'block'
  }, {
    queue: false,
    duration: 1000
  }).delay(9000).animate({
    width: '0',
    display: 'none'
  }, {
    duration: 1000
  });
  //$('#sideModal').css('display', 'none');I commented this out because this prevents the div showing in the first place.
}

#sideModal {
    height: 75px;
    width: 0;
    position: fixed;
    bottom: 2%;
    left: 0;
    background: #000;
    z-index: 1000;
    display: none;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="container" style="margin-top:35px;">
<button class="btn btn-warning" onclick="showModal()">Click Me</button>
<div id="sideModal">
  I'm a sliding modal
</div>
</div>





div滑入滑出。但是,文本仍然存在。我怎样才能解决这个问题?

最佳答案

您需要将overflow: hidden添加到#sideModal



function showModal() {
  $('#sideModal').css('display', 'block').animate({
    width: '20%',
    display: 'block'
  }, {
    queue: false,
    duration: 1000
  }).delay(9000).animate({
    width: '0',
    display: 'none'
  }, {
    duration: 1000
  });
  //$('#sideModal').css('display', 'none');I commented this out because this prevents the div showing in the first place.
}

#sideModal {
    height: 75px;
    width: 0;
    position: fixed;
    bottom: 2%;
    left: 0;
    background: #000;
    z-index: 1000;
    display: none;
    overflow: hidden;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="container" style="margin-top:35px;">
<button class="btn btn-warning" onclick="showModal()">Click Me</button>
<div id="sideModal">
  I'm a sliding modal
</div>
</div>

关于javascript - 弹出窗口,会滑动,延迟然后自动滑出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52552834/

10-10 02:01