React on DOM changes caused by Data Binding in Polymer - data-binding

while exploring the pure awesomeness of Polymer and Dart I struggle to get some things animated right after they get inserted to the DOM by Data Binding.
Example:
<template repeat="{{item in items}}">
<my-item item="{{item}}"></my-item>
</template>
Everytime a new item is inserted or an old one is removed I would like to animate these changes.
Currently I am doing something like this, which works but isn't really nice:
<style>
[item] { transition: 300ms ease-in-out; transform: translateX(0); ]
[require-start-animation] { transform: translateX(-100%); }
</style>
<template repeat="{{item in items}}">
<my-item item="{{item}}" require-start-animation></my-item>
</template>
and before removing it, I add 'require-end-animation' to the elements which will be removed.
The solution works but isn't really that great since I have to keep track of a lot of stuff such as adding the correct attributes at the correct time and removing it. React to transition ending and so on.
Thus I am asking you, is there a cleaner way to react on changes to the DOM which are caused by Data Binding?

You could create a mixin which overrides attached and detached and does the attribute setting/removal before forwarding the call to super (the element itself) and then apply this mixin on elements you want to animate.
I haven't used mixins a lot myself yet. If mixins don't work well for this you could create an implementation in a normal class and then forward the calls to attached and detached to this implementation.
It could also work to create a wrapper element that just wraps the element you want to animate and implements the animation on attach/detach.

Related

css animation not work. is there a problem with my code

its is very simple problem
so i just copied css from https://github.com/jh3y/whirl/blob/dist/css/building-blocks.css that give loading animation in css and i want it to apply it to my react project
I'm sure I included correctly, but it still doesn't work. and i am just doing like this
<div className="building-blocks" />
but its not working. is there any problem with the css code or can you show me how to do it correctly
its not the classname, it should be animation name, you can name your div class whatever you want!
.building-blocks {
animation: building-blocks;
}

Fade images when loaded and changed in Blazor (server) app

I've got a Blazor server app which displays a grid of images. I want to have the images fade when they're displayed. I'm currently using a CSS style/animation:
.gridimage {
animation: fadeIn ease 1s;
}
<img class="gridimage" src="#ImageUrl">
This works fine on initial page load - but when a user changes a filter criteria and the grid of images changes, my #code updates the #ImageUrl and I call StateHasChanged, but the fade doesn't kick in, because the image has already loaded.
I've thought about trying a different approach, where I define a JS method:
function fadeIn(obj) {
obj.style.transition = "opacity 1s";
obj.style.opacity = "1";
}
and then detect DOM changes and trigger that fadeIn() call when the img src attribute changes, but that feels kindof like fighting with the Blazor DOM update model. I've also toyed with using JSInterop when I update ImageUrl but again, it seems messy.
Is there a more elegant way to do it?
Turned out that Brian Parker's answer was correct; adding a unique #key to the item caused the CSS to re-trigger when the page transitions and the image updates - presumably because Blazor sees the <img #key=1234> item as different to <img #key=1235> and so forces it to re-evaluate the CSS.

Angular 2 animating height-propery -Timing on binding

I'd like to have a component, I called it information-board, to animate away after some seconds. I had the idea to make it slide up as exit-animation.
My approach for this is quite simple, since I can do this with css-animations regarding to this thread: Angular 2 Slide Up and Down Animation
My scss-file is looking quite simple:
.info-board {
transition: height 1s;
overflow: hidden;
}
The problem arises in the sentence from the mentioned thread: The height set to 'auto' can't be animated. This makes sense, I guess, but causing me a heap of trouble, because my information-board should be a shared component and also be allowed to be invisible at the start, only being shown when something interesting happens.
So, looking at my component-html:
<div *ngIf="informationMessage">
<div #contentElement class="info-board" [style.height]="contentHeight">
<alert type="{{alertType}}">
<strong>{{ informationHeading }}</strong> {{ informationMessage.messageText }}
</alert>
</div>
</div>
Nothing too fancy: If the informationMessage, a simple dto, is set, it should be shown. I set the height via binding in order to animate it properly.
Now the complicated part: If the info-board is not shown at the beginning, I basically need to wait for the dto to be set AND the html to be rendered. The only hook I found so far is the "afterViewChecked" one, leading to this Code:
#ViewChild('contentElement') public contentElement: ElementRef;
ngAfterViewChecked(): void {
this.checkSetBoardSize();
}
private checkSetBoardSize() {
if (this.contentElement && this.contentElement.nativeElement) {
this.contentHeight = this.contentElement.nativeElement.scrollHeight + 'px';
}
}
This event is the only one I can be sure, that the ViewChild is set, but it seems to be too late: Since this is the last step of the changetracking-logic, the height I set is ignored.
The only other hook, which looked helpful was "ngAfterContentChecked", but in this one, the ViewChild is not set.
I also didn't find a possibility to 'retrigger' the changetracking nor did the approach on Angular 2 #ViewChild in *ngIf with ViewChildren work for me.
Am I missing some sort of possibility? I know, that working with the nativeElements isn't a good idea, but from my research, this is currently needed working with heights.
You could use the animation feature of Angular, the example for ur case can be found in the angular docs
Sidenote: Be aware that the usage of the animation package (it's outsourced to #angular/animations) is changing in angular version >4.0.0-rc.1. For more the the changelog of angular

Inheritance of animation keyframes of element

I've got an element .shake and when it's :hover an animation starts. I need to inherit the shake element properties and its animation :hover effect.
I've got
.inherit-shake {
.shake;
}
It doesn't work because .inherit-shake just inherits the primary .shake properties but its :hover animation.
Is there a way to do that using Less?
If the rules for .shake and .shake:hover were written like in the below snippet then your current code should work as-is.
.inherit-shake {.shake;}
.shake{
a:a;
&:hover{b:b;}
}
However, I think they are written like below and that is the reason why the :hover rules don't get applied to .inherit-shape selector.
.inherit-shake {.shake;}
.shake{a:a;}
.shake:hover{b:b;}
The best solution would be to use the model mentioned in the first snippet. However, if you can't change the source mixin's for whatever reason then the best would be to make use of extend function with all keyword like in the below snippet:
.inherit-shake {&:extend(.shake all);}
.shake{a:a;}
.shake:hover{b:b;}
The all keyword within extend function would make sure that .inherit-shake:hover gets the same properties as applicable for .shake:hover. The compiled CSS output would be like below:
.shake, .inherit-shake {a: a;}
.shake:hover, .inherit-shake:hover {b: b;}
Added advantage of using extend function is that it would automatically group selectors (like in the output shown above).

How to use scrollRevealJS alongside AnimateCSS?

I love both the scrollRevealJS and AnimateCSS libraries for animations, however, I would like to use them both on one element. For example, I have a div <div class="animated fadeInDown" data-sr='enter top reset'>Lorem Ipsum</div>. For some reason, adding the Animate CSS classes animated fadeInDown ignores scrollReveal's data attribute. How am I able to use both the classes and data attributes of both libraries?
EDIT: I forgot to mention that I have the following style applied:
[data-sr] { visibility: hidden; }
The ScrollRevealJS library does not provide default functionality to work with AnimateCss. Instead of ScrollRevealJS you can use Wow.js library – it works with AnimateCss. The problem with Wow.js is that a reset option is not available.

Resources