javascript - smoothState.js - Identifying the referring page -
when clicking on link smoothstate loads new page's content, i'd identify referring page class visible on new page. there way this?
this isn't dynamic solution, ended doing setting classes anchor tags on referring page. smoothstate has onbefore() callback, passes $currenttarget, i.e. anchor element clicked start transition. read href off anchor element , detect want way (or store off somewhere until later).
so in html, declare link so:
<a href="new_page.html" class="special_case">new page</a>
then when i'm setting smoothstate, declare onbefore() callback:
onbefore: function( $currenttarget, $container ) { if ( $currenttarget.is( ".special_case" ) ) { // logic here globalspecialcase = true; } }
since smoothstate keeps in same place , ajax call request new page html, swaps out page content, current javascript environment remains, global variables , all. set global flag (or make whatever data structure want), , case special link, set flag.
at new page load, smoothstate runs onready(), signals it's got new page content , ready replace , run intro animations. check flag here things before page starts rendering, or wait until onafter() callback happens, means page loaded , transition animations have run. @ point, check flag, run logic, , unset make sure i'm ready new link click later.
onready: { duration: 0, render: function( $container, $newcontent ) { if ( globalspecialcase ) { // logic because page loaded special link globalspecialcase = false; } // inject new content $container.html( $newcontent ); } }
one thing note: pretty smoothstate examples have onready duration set 0, means onafter() callback happen following onready(), regardless of how long animations take. if want onafter() wait until animations done, make sure set duration milliseconds animations take.
Comments
Post a Comment