Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
In layerJS, the layout of the page is fully controlled by the hierarchy of stages, layers and frames and their attributes. Links control how this layout is dynamically changed upon user interaction.
Using links for triggering the transition has 3 advantages. First, it's easy using a mechanism that is known since the beginning of HTML. Second, every transition creates a new history entry. You can use the browser back and forward buttons to navigate through your application. Third, connecting the UI state with the URL allows you the create deep links into your application.
All interactions possible in layerJS can be triggered by regular links. layerJS provides different "router" modules that "run" those interactions. The hashrouter is the simples router and is active by default.
In it's simplest form you just need to mention a frame name after the '#' sign.
Note: frame1 should be a unique name as the link above does not mention any layer. layerJS will search all layers in the site and will do the transition in the layer that contains "frame1".
This can be accompanied by transition paramaters defining the transition type ("p") and the duration ("t")
There exist the special frames !next, !prev and !none that determine the frame to be changed by context. !next and !prev will activate the frame after or the frame before the current frame. !none will show no frame. You need to supply a layer as context.
You can combine transitions in different layer within one link:
The above will fade in a popup frame called "popup" while at the same time fading out the menu.
The file router allows transitions between frames in different HTML files. The is useful if you would like to spread content between different site for load times and SEO reasons. To use first enable the file router:
<body lj-router="filerouter"> ...
Then use a link the refers the file with the frame to be loaded
The filerouter will load the other files as an ajax request (Note: it needs to be on the same domain or CORS needs to be active on the server). It will analyze the stage-layer-frame hierarchy of the new file, matches common parts with the current file and adds new frames to the current hierarchy. Then it identifies the frames that should be active in the new file and does the correponsing transitions in the current file.
Important The structures of the files need to be similar. For example
file1.html <body lj-type="stage" lj-router="filerouter"> <div lj-type="layer" id="contentlayer"> <div lj-type="frame" id="frame1"> </div> </div> </body>
file2.html <body lj-type="stage" lj-router="filerouter"> <div lj-type="layer" id="contentlayer"> <div lj-type="frame" id="frame2"> </div> </div> </body>
<a href="./file2.html"></a> will dynamically add "frame2" to "contentlayer" in the current page and do a transition from frame1 to frame2.
Note: the static router is currently being revised and not working in the current version
The static router allows you to add absolute urls that are connected to states, a list indicating which frames are active in which stages.
will add a static route that will transition to frame1 if a link to “/frame1” is clicked. More complex scenarios are possible
will trigger transitions in layer1 and layer2 if the user goes to /awesome.
to the layer, the state of that layer is not shown in the url. This is helpful for opening and closing menues, etc. so for state changes that you don't need to save in a deeplink or want to go through in history.
Interstage transitions allow sending frames from one stage to another, creating effect like "zooming" a card in a grid to fullscreen while leaving all other cards in the grid.
Interstage transitions work similar as normal transitions. You simply need to specify the target layer in front of the frame. Here is an example with the has router:
You can move the frame back with:
Note: both transitions will make frame1 the active frame in the target layer. if that is not desired use '$' at the end of the path :