Khrys Khrys - 2 months ago 25
CSS Question

Pulsate bootstrap modal backdrop

Is there a way to "pulsate" the modal backdrop going from 50% red to 100% red and going back to 50% red and infinity looping?

http://jsfiddle.net/j8n5u8xy/

<a title="Sobre" data-placement="bottom" data-toggle="modal" href="#Sobre" class="btn btn-primary"> <i class="fa fa-quote-left"></i> </a>
<div class="modal bs-modal-lg" id="Sobre" tabindex="-1" role="dialog" aria-labelledby="SobreLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header alert-danger">
<h4 class="modal-title" id="myModalLabel"><i class="fa fa-warning"></i>Danger</h4>
</div>
<div class="modal-body" style="padding-top: 15px; padding-bottom: 25px;">
<h2>Danger!</h2>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>


Bootstrap has 2 build in classes:

.modal-backdrop.fade {
filter: alpha(opacity=0);
opacity: 0;
}
.modal-backdrop.in {
filter: alpha(opacity=50);
opacity: .5;
}


Is it possible to alternate between both in a amount of time, 2 seconds, for example?

Thanks

Answer

You should use css animations. This is just one example of what you could do, but you should play around with different sub-properties that the animation property has.

.modal-backdrop {
  background-color: red;
  animation: warn 2s infinite alternate;
  -webkit-animation: warn 2s infinite alternate;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes warn {
    from {opacity: 0;}
    to {opacity: 0.5;}
}

@keyframes warn {
    from {opacity: 0;}
    to {opacity: 0.5;}
}

For more info about support in different browsers, see this link by CSS tricks. Here's your updated jsfiddle