javascript - How to animate one element on top of another element in Angular 2? -


in angular 2, how animate 1 element it's size , position match of target element? target element's size , position not fixed, can vary @ runtime. attached complete example using jquery. bonus, i'm wondering if animation can done without using elementref?

codepen

see pen animate element on top of another matthew banz (@battmanz) on codepen.

html

<section>   <button id="animateblue">animate blue</button>   <button id="randomizeorange">randomize orange</button> </section>  <section>   <div class="ball" id="ball1"></div>   <div class="ball" id="ball2"></div> </section> 

css

body {   margin: 0;   padding: 0; }  section:first-of-type {   padding: 10px;   text-align: center;   background-color: #ccc; }  .ball {   border-radius: 50%;   position: absolute; }  #ball1 {   background-color: blue;   z-index: 5; }  #ball2 {   background-color: orange; } 

js

const ball1 = $('#ball1'); const ball2 = $('#ball2');  function getrandomintinclusive(min, max) {   return math.floor(math.random() * (max - min + 1)) + min; }  function randomlyassignorangepositionsize() {   const radius = getrandomintinclusive(10, 200);   const top = getrandomintinclusive(50, 300);   const left = getrandomintinclusive(10, 900);    ball2.css({     width: radius,     height: radius,     top: top,     left: left   }); }  ball1.css({   width: 50,   height: 50,   top: 100,   left: 50 });  randomlyassignorangepositionsize();  $('#randomizeorange').click(randomlyassignorangepositionsize);  $('#animateblue').click(function() {   ball1.animate({     width: ball2.css('width'),     height: ball2.css('height'),     top: ball2.css('top'),     left: ball2.css('left')   }); }); 

i'll go ahead , answer own question. turns out not possible in angular 2 of rc5. in order perform animation, need compute styles @ runtime. open feature request on github:

feature request: allow binding expression in style(), keyframes() etc...

in particular, checkout comment @dpix , answer @matsko.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -