Dogstudio / highway

Highway - A Modern Javascript Transitions Manager
https://highway.js.org/
MIT License
1.43k stars 92 forks source link

Conditional transition? #5

Closed jesperlandberg closed 6 years ago

jesperlandberg commented 6 years ago

Hi again,

This is not an issue, more of a question on how this would be done in the most effecient way.

I know one can set different transitions for different renderers, but is it possible to change transition depending on other stuff, like how would I do something like this:

transitions: {
  'default': document.body.classList.contains('is-open') : TransitionOne : TransitionTwo
}

I guess I could just do my conditional stuff inside the transitions file but separating them into two transitions would be cleaner.

Anthodpnt commented 6 years ago

Hi @jesperlandberg,

Yes you'll have to do your conditional stuffs in your transitions. The Highway.Core is called once to setup Highway with the renderers and transitions.

This means that once it's called it's not aware of any DOM changes. If you want to watch DOM changes and change the transition you'll have to work within the transitions.

This way when the transition is called, if the body has the classname is-open you can change it. I'm curious, what kind of transition would you like to do ?

Because if it's an animation when a menu or something is opened this shouldn't be part of the transitions of Highway but more a transition in a file like header.js for example that would be called when the menu button is triggered... Assuming this is the kind of animation you want to achieve.

So in conclusion, you can't do this kind of conditional statement when calling Highway.Core and I don't think this is a feature coming in next version since I don't think it's an intended behaviour for this kind of library.

Best regards, Anthodpnt

jesperlandberg commented 6 years ago

Hi @Anthodpnt

I understand:) no problem, will do my check in the transition.js file!

Well basically, I have a mask element that I animate on transition, but when the menu is open during a transition, I will use the menu element as the mask, for the out part of the transition. No big deal and is easily made with conditionals inside the transition file. I attached a video clip if ur interested in seeing what I mean. Another option is just giving the default mask transition a delay and triggering my close menu method on NAVIGATE_OUT, so that the mask animation starts after the menu is closed... but that makes the whole switching pages to long=)

transition.zip

Loving the library so far btw! Good job:)

Anthodpnt commented 6 years ago

Really nice work @jesperlandberg ! I would like to share this site when it will be live to show what is possible with Highway if you agree :).

jesperlandberg commented 6 years ago

@Anthodpnt of course:) Will send over a link when live!:)

Anthodpnt commented 6 years ago

@jesperlandberg Thanks ! Closing the issue.