Angular ngAnimate causes width animations to jump - css

I am using Angular with ngAnimate for a couple of cases. In another, I have a directive that is changing the width of the column (using Bootstrap col-md-* classes) and a simple transition that looks like this:
.column-view .column {
transition: width 1s;
}
I am not explicitly using ngAnimate here, but it is certainly causing me grief simply for being included. Basically, the transition jumps to zero before transitioning to the new width. If I remove ngAnimate from my module, the transitions are smooth, but I need ngAnimate for other features in my app.
Can I disable whatever ngAnimate is doing to my plain CSS transition? What can I do here to fix this? Driving me crazy.
Here is a fiddle demonstrating the problem. See the comments for instructions to reproduce.

NOTE: I used current latest version (AngularJS 1.2.6) to investigate your issue.
I found there is a "blockTransitions" function being called internally, which does just that: it blocks transitions.
https://github.com/angular/angular.js/blob/master/src/ngAnimate/animate.js#L1099
If you comment the line linked above (the single line of the "blockTransitions" function body), the problem is solved.
As I can't tell if this is a proper solution (and probably it is not), I've just created a PR so they can properly resolve the issue:
https://github.com/angular/angular.js/pull/5552
Also using latest version, there is a workaround: http://jsfiddle.net/2fnhr/3/
app.config(function($animateProvider){
$animateProvider.classNameFilter(/^((?!col-md).)*$/);
});
This will only apply the ngAnimate stuff for classes which does not contain "col-md" on its name, thus turning off the ngAnimate for the Bootstrap classes in question.
Explanation of the regular expression here: https://stackoverflow.com/a/406408/370290

Related

SWUP changing CSS files and the effects on fade in animations (HeadPlugin)

Hi I encountered a problem with how the HeadPlugin is effecting animations and determined a work around and thought I'd post it here, in-case anybody is running into the same issue. Also all of this may be misinformed and I might be missing something so please let me know.
The Scenario:
Let us say we want to use different stylesheets for different pages on our site, then we can use the HeadPlugin to do so.
The Problem:
When changing stylesheets the fade out animation will work but the fade in animation will not work.
(note: if the elements within the stylesheet have the same name in the two pages being transitioned between the fade in animation will work some of the time, depending on the element and the animation.)
A Solution:
To create a separate stylesheet defining all the animations between all your pages and include it in every html page. Then have a separate stylesheet for the rest of the styling for the individual pages or as you see fit. This way you can still style the rest of your elements sharing the same ids/classes differently between pages.
(Drawback: initial load time of the stylesheet containing all the animations, but this file should be lazy loaded :D)
Another Solution (me no like) :
Have one big stylesheet with the styles for all the elements in every page (excluding the inline CSS of course).
(Drawback1: initial load time of the stylesheet containing all the animations and other styles, this file should not be lazy loaded, unless you split the animation CSS and non animation CSS into separate files. In which case just the initial load time of your style file, unless all the critical styles are done inline in which case you could lazy load both files XD.)
(Drawback2: can't have elements sharing the same ids/classes on different pages unless using inline CSS to define the differences.)
Potential solution? (haven't tried):
Using inline CSS to define the animations O_O, idk if this is even possible but probably not a good idea.
I can post some examples demonstrating the problems etc if anybody needs.
If there is a belter way then pls let me know, otherwise hope this helps OwO.

CSS pseudo :dir(); :host-context() and directionality based styling

In this question I'm looking for the cleanest possible solution for the problem below, along with urging the browsers' coders to catch up with the spec, especially :dir() one!!
The problem and it's current best known to me solution:
I'd like to style the image below based on directionality, flipping it, for example, when in RTL mode. The image resides in a shadow DOM. As of now, I'm achieving that with the styling below.
::shadowRoot
<style>
.directed-image:dir(rtl) { transform: rotateY(180deg); } -- Firefox only as of now
:host-context([dir=rtl]) { transform: rotateY(180deg); } -- Chromium only as of now
</style>
<img class="directed-image" src="..." />
Issues yet to be solved:
None of the styles above helping Safari: it has not yet implemented :dir() pseudo class and it's people seems to have a strong objection to :host-context()
I'm really not fan of those double-done solutions for a platform's diversity; would like to get rid of those, but this is only a secondary concern
Solutions ?:
The best I'd wish to have is that :dir() will get wide cross browser support - it'll solve the Safari's issue as well as would provide a truly directionality context aware styling (downsides of [dir=ltr] are touched a bit in the WebKit's bug link above).
But given that
Chromium's bug on :dir() is staled from 2018
WebKit's bug on :dir() last touched at 2016!!!
Firefox's bug on :host-context() is staled from 2018 with some concerns about the spec
and unwillingness of WebKit to implement :host-context()
-- having all this: is there any other solution for the problem (looking to solve the Safari issue at first priority).
JS based solutions are interesting but much less preferred.
january 2020 answer:
As you said: the dir attribute on the body tag will (in most cases) be the only indication of a language change. Since CSS doesn't cascade (yet; as you said) the only option for now is for Elements to observe that attribute change. So I fear your only option is a MutationObserver (in the elements you own)
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: false, subtree: false };
Not sure if this is what you are looking for, but you could use RTLCSS. It's a CSS framework that allows you to easily switch between and create RTL and LTR stylesheets, without having to do too much double work.
It also supports a couple of big CSS frameworks if you use those, like Bootstrap and Semantic-UI

Animating elements by change class in Angular2+

I need to add some animation to my Angular project, and best way I came up with is just make from classname a variable and switch it in .ts file(if I need to attach style to event for example). So that mean a have two(or more) css style sets to make an animation do what I want...
Questions is:
1) Is it bad in any other way than just a lot of css code? I mean I'm fine with that, just wanna know is other people do the same? Cause its feels a bit like nasty coding...
2) I heard about angular core animation, do I have to use it here?
Thank you!
Assigning classes works really well in angular, I actually prefer using CSS for animation rather than the angular libraries.
To assign classes on certain conditions, you can use the following notation in your template:
<div class="card" [class.card--inactive]="yourCondition">
This will add the class card--inactive to the div whenever yourCondition is true.

Animation or transition just using style attribute inside a tag

It is possible?
I mean this:
<div style="?css animation?"> Content </div>
It can be any tag, or maybe triggering the animation or transition from other tag.
This question is because I will like to use animations and transitions in a web app, but this app just let me use css included in the style tag attribute.
Pseudo clases I guess are out of the question so I can not trigger transitions, neither I can use javascript, so onmouseover or similar kind of stuff are out of the question.
Animations on the other hand needs their keyframes settings, and I can not set keyframes inside a style tag.. (or can I?). I read something similar here:
https://css-tricks.com/animate-to-an-inline-style/
But I guess it would not work for what I am asking.
Not sure if there is a hack to import a css from an attribute or just achieve animations in chrome browsers (another thing, I have not access to the head section of the html).
Yeah I know, it seems mission impossible, I was just wonder in case there is some kind of trick to achieve this even if the animation is very limited.
Thanks for your time.
No, afaik.
Atleast not for those animations that require :hover or keyframes as you mentioned. However, it is possible by including animations attached to <style> contained within the same html page. Or by injecting css code using js code on the same html page . This suits if you are okay with CSS resting in the same file.
The link you've mentioned is NOT using inline CSS for animation; it has a separate CSS file.

How to use css to find a list element in css alone, i.e. not be css3 dependent?

I'm trying to select a element with css and I can't use css3 because this is for a older system, so I can't use.
nth-last-child(2)
is there a way to do this in css
You can add a class using jQuery like such:
// #css3 and .query can be any css3 selector
$("#css3 .query:nth-last-child(2)").addClass("lasties2")
And then define the class (lasties2) in your css.
If you can't use JavaScript or are using a different library, or don't want to use a library, then please specify. Other libraries like mootools and prototype will have ways to achieve the same end. You will have greater difficulty with pure JavaScript in an environment that does not support CSS3, but it is possible. If you can't or don't want to use JavaScript then you will have to add a class to the relevant items manually.
One caveat of the javascript and the manual approach is that if the page is modified by javascript, the behavior won't match css3. With CSS3 if the nth from last child changes, it then the new one will get styled, with jquery or manual classing it will stick to the initial one. Here is a jsfiddle that illustrates what i mean: http://jsfiddle.net/CSExB/35/
As you can see if you tried the fiddle, it is possible to fix this with javascript by first removing the class, then making the modification and finally reapplying the class, for the above code for example it would be:
$("#css3 .query:nth-last-child(2)").removeClass("lasties2");
$("#css3").append('<p class="query">something</p>');
$("#css3 .query:nth-last-child(2)").addClass("lasties2");
If you want make page compatible with IE < 9 or Safari < 3.2 you should add additional class to list items <li class="some_additional_class">. You can do it when page generated on server-side, or using JS on client-side.

Resources