CSS Transition not working with ng-class - html

I'm attempting to create a CSS transition when an element receives a certain class. So far the toggle change works (which means that ng-class is working properly), but the animation doesn't happen.
Here's my code:
.intro-text{
height:auto;
-webkit-transition: height 200ms ease-out;
-moz-transition: height 200ms ease-out;
-o-transition: height 200ms ease-out;
transition: height 200ms ease-out;
}
.intro-text.hide{
height:0;
}
And the HTML:
<div class="intro-text" ng-class="{'hide':clicked}">
<h1>Howdy stranger!</h1>
<h3>Use the form below to search for an artist and start building your record collection!</h3>
</div>
What am I missing?
EDIT: I've narrowed the problem down to bootstrap. If I include the bootstrap.min.css, the animation doesn't work, without it, it works perfectly. Any idea why guys?
EDIT 2: Fixed it! The problem is that both .hide and .hidden are classes defined in Bootstrap, so it was overriding my styles, parsing a display:none; before the animation was visible. When changed the class to another name, it got fixed : )

Actually your issue is not about Angular + ng-class, but about a css3 transition between height: auto and height: 0.
Here is a SO question about this: http://jsfiddle.net/Y3uxy/
The solution is to do the transition on max-height instead of height, and to set max-height to something big enough.
.intro-text{
max-height:999px;
overflow: hidden;
-webkit-transition: max-height 200ms ease-out;
-moz-transition: max-height 200ms ease-out;
-o-transition: max-height 200ms ease-out;
transition: max-height 200ms ease-out;
}
.intro-text.hide{
max-height:0;
}
Here is a demonstration: http://jsfiddle.net/Y3uxy/

Related

CSS animation on after element doesn't appear to do anything?

I believe it's possible to add css to pseudo elements in CSS even though it is a working draft currently.
However, upon trying in the latest version of Chrome I can't seem to get it working.
I want the :after element on my header to transition in instead of looking so blocky.
I have added the transition to my after element but it's still the same, have I specified the CSS as below;
#main-header:after {
height: 95px;
content: " ";
width: 100%;
left: 0;
position: absolute;
background: url(http://stbenedicts.justinternetdns.co.uk/wp-content/uploads/2016/07/waves-test-1.png) top center;
z-index: 1;
top: 144px;
}
#main-header.et-fixed-header:after {
-webkit-transition: background-color 0.4s, color 0.4s, transform 0.4s, opacity 0.4s ease-in-out;
-moz-transition: background-color 0.4s, color 0.4s, transform 0.4s, opacity 0.4s ease-in-out;
transition: background-color 0.4s, color 0.4s, transform 0.4s, opacity 0.4s ease-in-out;
top: 54px;
}
So that when scrolled, the after element should ease in and not be one solid movement.
Any advice?
EDIT: http://stbenedicts.justinternetdns.co.uk/ <- playground
I'm working on the assumption that the transition(s) are supposed to take place when the .et-fixed-header is added.
But what are you transitioning?
transition:
background-color 0.4s,
color 0.4s,
transform 0.4s,
opacity 0.4s ease-in-out;
But from what to what?
You aren't setting initial values for those properties or end values.
The only thing you are changing (except the background, kinda) is the top value and you aren't transitioning that at all.
So you would need to set actual values on your #main-header rule to start with and new different values on your #main-header.et-fixed-header rule
Try setting the transition properties (-webkit-transition, -moz-transition, transition) on the base class (#main-header:after).
#main-header:after {
height: 95px;
content: " ";
width: 100%;
left: 0;
position: absolute;
background: url(http://stbenedicts.justinternetdns.co.uk/wp-content/uploads/2016/07/waves-test-1.png) top center;
z-index: 1;
top: 144px;
-webkit-transition: all 0.4s, color 0.4s, transform 0.4s, opacity 0.4s ease-in-out;
-moz-transition: all 0.4s, color 0.4s, transform 0.4s, opacity 0.4s ease-in-out;
transition: all 0.4s, color 0.4s, transform 0.4s, opacity 0.4s ease-in-out;
}
#main-header.et-fixed-header:after {
top: 54px;
}
By defining the transition on the base class the browser knows to transition when the modified condition — the addition, presumably, of et-fixed-header in your example — occurs. Otherwise, it only applies the transition properties to the class when that condition is present; meaning that you would only see the transition if/when that modifier is removed. This article does a far better job of explaining it.
EDIT: I hadn't noticed you were only specifying background-color for your transition property. In addition to moving the transition properties to the base class, you'll have to either add the other properties (the syntax is explained here, or broadly transition all properties

How to collapse in the bootstrap nav from right side? [duplicate]

Is there a way to collapse the the Bootstrap Collapse plugin from horizontally instead of vertically? Looking at the code this ability doesn't seem to be built in, but I'm hoping I'm just missing something...
Any help will be greatly appreciated. Thanks!
I figured out how to do this very easily without modifying or adding any javascript.
First you define the following CSS after all Twitter Bootstrap CSS:
.collapse {
height: auto;
width: auto;
}
.collapse.height {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition: height 0.35s ease;
-moz-transition: height 0.35s ease;
-o-transition: height 0.35s ease;
transition: height 0.35s ease;
}
.collapse.width {
position: relative;
width: 0;
overflow: hidden;
-webkit-transition: width 0.35s ease;
-moz-transition: width 0.35s ease;
-o-transition: width 0.35s ease;
transition: width 0.35s ease;
}
.collapse.in.width {
width: auto;
}
.collapse.in.height {
height: auto;
}
Next, on the target element (where you define the .collapse class) you need to add the class .width or .height depending on what property you want to animate.
Finally, you must wrap the contents of the target element and explicitly define its width if animating the width. This is not required if animating the height.
You can find a working example here -> http://jsfiddle.net/ud3323/ZBAHS/
With bootstrap 3.0.0, you just need to add the width class to the target element and then the following css if you want it to animate.
.collapse.width {
height: auto;
-webkit-transition: width 0.35s ease;
-moz-transition: width 0.35s ease;
-o-transition: width 0.35s ease;
transition: width 0.35s ease;
}
Updated 2019
Bootstrap 4.x
Bootstrap 4 horizontal collapse transition is basically the same, expected the visible class is now .show instead of .in. It also may help to specify display:block since many elements are now display: flex.
.collapse.show {
visibility: visible;
}
4.x horizontal collapse demo
4.x sidebar demo
Also see:
Bootstrap horizontal menu collapse to sidemenu
How to slide nav bar from left instead from top?
Bootstrap 3.3.7 (original answer)
None of the existing answers worked for me. To make the collapse animation horizontal in the latest versions you need to set both transition to width, and also use visibility.
.collapse {
visibility: hidden;
}
.collapse.in {
visibility: visible;
}
.collapsing {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition-property: height, visibility;
transition-property: height, visibility;
-webkit-transition-duration: 0.35s;
transition-duration: 0.35s;
-webkit-transition-timing-function: ease;
transition-timing-function: ease;
}
.collapsing.width {
-webkit-transition-property: width, visibility;
transition-property: width, visibility;
width: 0;
height: auto;
}
3.x demo
In my version of bootstrap 3 (using LESS), I simply had to include this in my global less file:
.collapsing.width {
width: 0;
height: auto;
.transition(width 0.35s ease);
}
The extra class has to be width since the collapse.js looks for this class for the transition. I tried everyone else's suggestions, but they didn't work for me.
It doesn't appear to be an option for that particular plugin. It looks like you may need to modify it or hook into it somehow to get it to work that way...
After looking at the JS file for a bit I noticed a couple things. First thing is that it looks like it might be using bootstrap-transition.js ,which appears to be using CSS3 transitions. So it might be possible to write a new transition. I am not 100% certain if that is how it is working though.
Option One
My suggestion would be to either poke around in the bootstrap-collapse.js plugin file for a while and see if you can figure out how it is working.
In particular I would look at this part... bootstrap-carousel.js
this.$element[dimension](0)
this.transition('addClass', $.Event('show'), 'shown')
$.support.transition && this.$element[dimension](this.$element[0][scroll])
It looks like .transition is a callback from bootstrap-transition.js
Option Two
My second suggestion would be to just write something of your own.
My Answer
And finally my answer is that from looking at the bootstrap documentation it doesn't appear to be an option.
Some additional info:
This website seems to be doing similar stuff with CSS3 transitions.
http://ricostacruz.com/jquery.transit/
i think translateX(-100%) and translateX(0) might be the way to go rather than animating width as uses hardware acceleration correctly when supported
Good answers here, but I had to make some modifications for a cleaner, two-way transition:
.collapse.width, .collapsing {
height: 25px; /* depending on your element height */
overflow: hidden;
-webkit-transition: width 0.25s ease;
-moz-transition: width 0.25s ease;
-o-transition: width 0.25s ease;
transition: width 0.25s ease;
}
Setting a fixed height also helped prevent page "jump" as the element collapsed and expanded.

Easing transition doesn't seem to work on delay

I have a div with fixed height and width and upon clicking the label(checkbox trick) I expand the div to 100% width and height. That works, however the issue is in the transition.
I wish to create a easing transition where first the width expands and then the height expands. However upon defining the transitions the easing doesn't happen, instead it's like transition timing function goes to step-end. The transition happens instantly without easing(even though the delay on height transformation works).
tl;dr: The transition loses smoothness
Example: jsFiddle
The properties can not be transitioned from different "metrics".
In the base state, you specify height in px; in the changed state, you specify it in percentage. That won't work.
You can set it to work somehow with some tricks, that are not fully satisfactory; the best of them is to use max-height to do the change
#cbox {
display:none;
}
.someDiv {
background: blue;
color: white;
width: 200px;
max-height: 100px;
overflow: hidden;
height: 100%;
transition-property: width, max-height;
transition-duration: 2000ms;
transition-timing-function: ease;
transition-delay: 0, 2000ms;
}
#cbox:checked + div {
width: 100%;
max-height: 1000px;
}
I have also writen the transition in a way that can save you some typing when using multiple properties; notice that I can write ease only once
fiddle
You should separate properties with comma, instead of writing them in same line, try this
CSS
-webkit-transition: width 200ms ease 0s, height 200ms ease 200ms;
-moz-transition: width 200ms ease 0s, height 200ms ease 200ms;
-ms-transition: width 200ms ease 0s, height 200ms ease 200ms;
-o-transition: width 200ms ease 0s, height 200ms ease 200ms;
transition: width 200ms ease 0s, height 200ms ease 200ms;

Show/hide div with link same link should also work for the tab content

The title may seem little bit confusing so I draw a sketch, so you can understand more what I want to achieve: https://www.dropbox.com/s/luoiz4erg4jfk8y/howitshouldwork.png
The tab function is based on liquidslider
I've start on the transition part, but I need some help...
CSS:
li a:onClick + .bottom {
-webkit-transition: height 0.3s ease-in-out;
-o-transition: height 0.3s ease-in-out;
-moz-transition: height 0.3s ease-in-out;
transition: height 0.3s ease-in-out;
bottom: 400px;
}
http://jsfiddle.net/ea9VT/1/
It should not be a scroll.
Can anybody explain how this should be done?
My Suggestion is you can use Jquery for this Animation. I hope this done very simple by using JQuery animate function.

CSS Transition not working properly

I have the following code: http://jsfiddle.net/8TG8L/
On another part of my HTML I can get the transition CSS to work great, but here on the right hand side I cannot get the transition to have any delay.
Relevant code:
.home_subvid_hover {
background-image:url('http://www.ptroa.com/images/video_hover.png');
/*background-repeat:no-repeat;*/
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
EDIT:
To clarify, please look at this code: http://jsfiddle.net/9UuY7/
That one works although it's the same principle as the first one, why is that?
Thanks,
The reason the background isn't animated, is because the backround-image isn't set on the initial class .home_subvid.
You can't animate background-image:none to background-image:url(...).
If you try this, it's gonna work:
.home_subvid {
background-image:url('http://placehold.it/1x1/000');
background-size: cover;
-webkit-transition: all 0.4s ease-in-out;
-moz-transition: all 0.4s ease-in-out;
-ms-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
.home_subvid:hover {
background-image:url('http://www.ptroa.com/images/video_hover.png');
/*background-repeat:no-repeat;*/
}
FIDDLE.
You can't transition background images from none to an image, see this document on MDN. Transitioning from image to image doesn't have amazing browser support either; as far as I know it's only supported in Chrome.
You can, however, create a similar effect with different markup/CSS.
How about an element made invisible with opacity: 0; and then transitioned into opacity: 1; when hovered?
Your css is changing the background image from nothing to an image, which the current generation of CSS can't animate.