Bootstrap obviously makes use of the 'hide', 'fade' and 'in' classes for its transitions.
The problem I'm having is that using 'fade' and 'in' will change the opacity from 0 to 1. The transition effect is perfect, but the content is still there taking up space on the page, even if you can't see it. For example, if it's container has a border, there'll be a big white space before the border.
I want to make use of their exisiting CSS transitions by adding and removing the 'in' class, but I also want whatever element that's fading out, to be hidden, but only after the transition is over. So basically, exactly what they do in the modal, but I don't know how they do it.
In my example below, adding or remove the hide means the div appears or disappears instantly, before the fade effect can happen.
JS fiddle here
Example HTML:
<div class="control-group">
<label class="control-label">Choose one:</label>
<div class="controls">
<label class="radio inline">
<input type="radio" name="color-radio" id="yellow-trigger" value="yellow" />Yellow Box</label>
<label class="radio inline">
<input type="radio" name="color-radio" id="red-trigger" value="red" />Red Box</label>
</div>
</div>
<div id="yellow-box" class="hide fade">
<p>I'm yellow</p>
</div>
<div id="red-box" class="hide fade">
<p>I'm red</p>
</div>
Example JS:
$(document).ready(function () {
$('#yellow-trigger').click(function () {
$('#yellow-box').addClass('in').removeClass('hide');
$('#red-box').addClass('hide').removeClass('in');
});
$('#red-trigger').click(function () {
$('#red-box').addClass('in').removeClass('hide');
$('#yellow-box').addClass('hide').removeClass('in');
});
});
The jQuery fadeIn() method is used to fade in a hidden element.
Step 1: Add bootstrap CDN to your HTML code. Step 2: For making a bootstrap carousel you have to add class = “carousel” in your HTML div box. Step 3: To create the carousel fade in and fade out transition instead of a slider you have to add a class=”carousel-fade”.
The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle.
In the CSS, use the @keyframes rule paired with fadeIn. At 0%, set the opacity to 0. At 100%, set the opacity to 1. This creates the fade-in effect.
Any reason not to just use jQuery for the fadeIn effect? Below is some code to make the fade in effect with jQuery.
Fiddle here
Removed "fade" class
<div id="yellow-box" class="hide">
<p>I'm yellow</p> </div>
Updated jQuery for fade in
$(document).ready(function () {
$('#yellow-trigger').click(function () {
$('#red-box').hide();
$('#yellow-box').fadeIn('slow');
});
$('#red-trigger').click(function () {
$('#yellow-box').hide();
$('#red-box').fadeIn('slow');
});
});
This is very old, but in case anyone else gets here, the answer is to use a single-shot handler for the synthetic event bsTransitionEnd
.
example:
$(".alert").one('bsTransitionEnd',function() {
$(this).addClass('hide');
});
window.setTimeout(function(){
$(".alert").removeClass('in');
},1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With