javascript - Changing CSS property on entering or leaving AngularJS state -
i've got app want change css property on entering/exiting angular state. css property background-color on html , body elements (basically backdrop) gets exposed on transitions between states. i'd change color of backdrop make transitions bit nicer. suggestions how can in angular?
ui-router
's $state
service broadcasts events on $rootscope
states change. listen these events , apply style changes accordingly. following cause body have red background during state transitions , white background after:
angular.module('myapp').run(function($rootscope){ $rootscope.$on('$statechangestart', function(event, tostate, toparams, fromstate, fromparams){ //change body background document.body.style.background = 'red'; }); $rootscope.$on('$statechangesuccess', function(event, tostate, toparams, fromstate, fromparams){ //reset body background document.body.style.background = 'white'; }); });
Comments
Post a Comment