Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple transition() on one element with no queue #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

annam
Copy link

@annam annam commented Aug 29, 2012

The problem was that on every transition() call, the css property "transition" got overwritten.

for example:

$(elm).transition({ opacity: 1, duration: 400, easing: 'ease', queue: false })
$(elm).transition({ rotate: 30, duration: 300, easing: 'in', queue: false })

would result in element css: "transition: rotate 300 ease-in"

i now merge the properties to generate the css: "transition: opacity 400ms ease, rotate 300ms ease-in"

also "unmerge" function allows to remove a property from the string (the whole string used to be cleared) when finished transitioning.

this also allows for the hardcoded "transition" properties on the element to be maintained, if we are transitioning some other property.

The problem was that on every transition() call, the css property "transition" got overwritten.

for example:

$(elm).transition({ opacity: 1, duration: 400, easing: 'ease', queue: false })
$(elm).transition({ rotate: 30, duration: 300, easing: 'in', queue: false })

would result in element css: "transition: rotate 300 ease-in"

i now merge the properties to generate the css: "transition: opacity 400ms ease, rotate 300ms ease-in"

also "unmerge" function allows to remove a property from the string (the whole string used to be cleared) when finished transitioning.

this also allows for the hardcoded "transition" properties on the element to be maintained, if we are transitioning some other property.
@facultymatt
Copy link

+1 trying this now

@rstacruz
Copy link
Owner

Thanks! Looks a little huge to review right now, hope you don't mind I'll look into it after 1.0.0.

At first glance I think the solution could be much simpler than this. Transit only has to add transitions when they start, and remove them when they end, all without disturbing whatever transitions are already set.

This means that everytime you add a transition, you have to keep a copy of what you added, and take it out later on.

Here's some almost-working code:

function addTransition($element, transition) {
  // Get the old `transition` value
  var original = $element.css('transition');

  // Concatenate it with the new, and set it
  var updated = transition;
  if (original.length > 0) updated = original + ", " + transition;
  $element.css('transition', updated);

  // Now, your browser will probably mangle what you added. For
  // instance, if you added "opacity 300ms linear", Firefox translates
  // that to "opacity 300ms linear 0s".
  //
  // Let's figure out what the browser changed it to. The .substr()
  // covers for the original transition string and the ", " we added.
  // Remove these transitions after the transition has ended.
  return $element.css('transition').substr(original.length+2);
}

@facultymatt
Copy link

Has there been any progress on this? Has this feature been added to the plugin yet? Thanks!

@thdxr
Copy link

thdxr commented Mar 13, 2013

I'm also interested in this, this plugin would be complete with this

@lucasmotta
Copy link

+1

1 similar comment
@chanpory
Copy link

chanpory commented Aug 4, 2013

+1

@ghost
Copy link

ghost commented Aug 12, 2013

I'm also very interested in this. the project I'm working on runs multiple animations at once, and they can be any combination. jQuery is a little slow with this since some of the image sizes are large, so it would be nice if the plugin could do this. awesome plug in btw!

@pingram3541
Copy link

For clarity, is this why when I stack/queue transitions, the queue works the first time, animating each transition separately but on subsequent triggers they happen together (even if I reset all inline styles, i.e. $('.item').attr('style',''))?

For example:

$('.item').on('mouseenter', function(){
  $('.item').transition({ x: "30px" }).transition({ y: "30px" });
});

The first mouseenter event animates 30px on x axis and once complete animates 30px on y axis. On any future mouseenter events, both the x and y animations happen at the same time rather than stacked unless I do something like this.

$('.item').on('mouseenter', function(){
  $('.item').transition({ x: "0", y: "0", duration: "0" }).transition({ x: "30px" }).transition({ y: "30px" });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants