javascript - Bezier curve trail generation animated -


http://codepen.io/anon/pen/xbeeze

<button class="move-me">start animation</button> <div class="circle">/div>  .circle { width: 20px; height: 20px; background-color: #ebc84e; border-radius: 100%; margin-top:50px; }    $('.move-me').on('click', function() { tweenmax.to(".circle", 2, {bezier:{curviness:2, type:"thru", values:[{x:0, y:0},{x:122, y:120},{x:239, y:0},{x:300, y:0},{x:411, y:120},{x:533, y:0}]}, ease:linear.easenone }); }); 

in codepen make circle go point point b. trying make circle generate line behind in end have bezier curve specified drawn on page.

any thoughts?

thank in advance!

try this:

  • add position: absolute; in css rule .circle object.
  • store reference $('.circle') object in variable named circleobject , use in tweenmax.to() call.
  • in tweenmax.to() call, add onupdate callback along onupdateparams , onupdatescope values being onanimationupdate, [circleobject] , this respectively.
  • create function named onanimationupdate parameter received name, circle so: function onanimationupdate(circle){...}.
  • add $(circle).clone().appendto(document.body); line inside newly created function.

here code in full:

css:

.circle {     position: absolute; // <-- added line     width: 20px;     height: 20px;     background-color: #ebc84e;     border-radius: 100%;     margin-top:50px; } 

javascript:

var circleobject = $('.circle'); // moved '.circle' here can passed parameter later on 'onupdate' callback  $('.move-me').on('click', function () {     tweenmax.to(circleobject, 2, {         bezier: {             curviness: 2,             type: 'thru',             values: [                 {x:0, y:0},                 {x:122, y:120},                 {x:239, y:0},                 {x:300, y:0},                 {x:411, y:120},                 {x:533, y:0}             ]         },         onupdate: onanimationupdate, // <-- added line         onupdatescope: this, // <-- added line         onupdateparams: circleobject, // <-- added line. read more these here: [http://greensock.com/docs/#/html5/gsap/tweenmax/].         ease: linear.easenone     }); });  function onanimationupdate(circle){ // <-- added function block     $(circle).clone().appendto(document.body); // <-- , of course, added this. line creates clone of '.circle' object , places '.circle' object i.e. cloning. } 

hope helps. here working jsfiddle.

p.s. there 1 thing needs said here. if looking draw stuff on web, should canvas api. more performant , flexible.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -