ded / morpheus

A Brilliant Animator
504 stars 57 forks source link

Passing an object reference to animate() sets duration to undefined after the first run. #50

Closed danjarvis closed 11 years ago

danjarvis commented 11 years ago

I have no idea if this actually a bug or not, and an easy work around is to just clone the object before passing it in... but I would like to confirm this behavior before I start doing that.

The reason I noticed this is because I'm working on a plugin for ender, and wanted to allow a consumer to override some animation defaults. I was using an extend(target, source) implementation to merge my default animation values with what was passed in, and I noticed that duration was getting reset after the first run.

Below is a simple code snippet which better conveys what I am trying to describe:

<html>
  <head>
    <title>Is this a bug, or am I just drunk?</title>
    <script type="text/javascript" src="//cdn.enderjs.com/ender.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function () {
        var props = { duration: 250, 'margin-top': '+=32px' };
        $('#dat_button').on('click', function () {
          console.log('props.duration: ' + props['duration']);
          $(this).animate(props);
        });
      });
    </script>
  </head>
  <body>
    <button id="dat_button">Click Me</button>
  </body>
</html>

The first click of dat_button will log a duration of 250 and the button will move down 32px after 250ms. The second click of dat_button will log a duration of undefined and the button will move down 32px after 1000ms.

danjarvis commented 11 years ago

Perused the source and messed around with this a bit more tonight... not a bug. Moving along...