javascript - jQuery & Bootstrap Slide Up Alert - Stack Overflow

I have an alert:<div class="alert alert-success fade show" id='success-alert' ro

I have an alert:

<div class="alert alert-success fade show" id='success-alert' role="alert">
        {{ message }}
      </div>

I have a button:

<input name="submit" value="Submit" class="btn btn-primary" id="submit-id-submit" type="submit" method="post">

When the button is clicked, the alert appears. I want the alert to slide up slowly using jQuery's .slideUp(). Here is my attempt:

<script>
  $(document).ready (function(){
              $("#success-alert").hide();
              $("#submit-id-submit").click(function showAlert() {
                  $("#success-alert").fadeTo(2000, 2000).slideUp(500, function(){
                 $("#success-alert").slideUp(500);
                  });
              });
   });
</script>

This causes the alert to appear, and then abruptly disappear quickly (shorter than two seconds). I believe the alert is somehow being called twice, because when I change the 500 (all three) to 2000, the alert shows up, it slides up correctly, then a new alert appears and abruptly disappears.

How should I achieve the slow slide up, once?

I have an alert:

<div class="alert alert-success fade show" id='success-alert' role="alert">
        {{ message }}
      </div>

I have a button:

<input name="submit" value="Submit" class="btn btn-primary" id="submit-id-submit" type="submit" method="post">

When the button is clicked, the alert appears. I want the alert to slide up slowly using jQuery's .slideUp(). Here is my attempt:

<script>
  $(document).ready (function(){
              $("#success-alert").hide();
              $("#submit-id-submit").click(function showAlert() {
                  $("#success-alert").fadeTo(2000, 2000).slideUp(500, function(){
                 $("#success-alert").slideUp(500);
                  });
              });
   });
</script>

This causes the alert to appear, and then abruptly disappear quickly (shorter than two seconds). I believe the alert is somehow being called twice, because when I change the 500 (all three) to 2000, the alert shows up, it slides up correctly, then a new alert appears and abruptly disappears.

How should I achieve the slow slide up, once?

Share Improve this question asked Dec 5, 2017 at 19:58 OverflowingTheGlassOverflowingTheGlass 2,4342 gold badges34 silver badges80 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The classes "fade" and "show" are the reason for the weird behavior in your code.

Is this what you're looking for?

JS FIDDLE DEMO

I got rid of those classes and added some CSS.

Relevant code:

$("#submit-id-submit").click(function () {
    $("#success-alert").show(); // use slide down for animation
    setTimeout(function () {
      $("#success-alert").slideUp(500);
    }, 2000);
});

Hope this helps. :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745372133a4624840.html

相关推荐

  • javascript - jQuery &amp; Bootstrap Slide Up Alert - Stack Overflow

    I have an alert:<div class="alert alert-success fade show" id='success-alert' ro

    22小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信