javascript - How to prevent a class from remaining active when stop() cancels the animation? -


i'm left stumped animation got, set class on navigation button turns 3 pins x when menu visible.

the problem when spam click button, possible x class active despite menu being out of screen. [most likely] caused stop() function since cancels out animation.

this i've tried far:

  • setting add/remove class in callback function of animation, sort of works looks ugly because sets 'x' after animation , doesn't work stop(), need.
  • i had 2 seperate directives, 1 handling animation , 1 sets different values etc navigation elements. ran 1 directive after other gives me same effect current, mashed up, solution.
  • and current attempt:

    nav.directive('navsettings', [function() {    return {     restrict: 'a',     link: function($scope, element, attrs) {        var windowheight = $(window).height(),           sitenav = $('#site-nav');        sitenav.css('height', windowheight + 'px');        element.on('click', function() {          var posleft = sitenav.position().left,             navwidth = sitenav.width();          posleft === -navwidth ? posleft = 0 : posleft = -navwidth;          if (element.hasclass('x')) {            element.removeclass('x');           sitenav.stop().animate({             left: posleft           });         }         else {            element.addclass('x');            sitenav.stop().animate({             left: posleft           });         }       });     }   } }]); 

    some html go along this:

    <div>   <div>     <button id="nav-toggle" data-nav-settings>       <hr ng-repeat="pin in [1, 2, 3]">     </button>   </div> </div> <aside id="site-nav">   <nav class="padding narrow" ng-controller="navctrl"></nav> </aside> 

    i don't else ensure doesn't happen.

    nav.directive('navsettings', [function() {     return {         restrict: 'a',             link: function($scope, element, attrs) {                 var windowheight = $(window).height(),                 sitenav = $('#site-nav');                 sitenav.css('height', windowheight + 'px');                 element.on('click', function() {                     var posleft, navwidth = sitenav.width();                     if (element.hasclass('x')) {                         element.removeclass('x');                         posleft = -navwidth;                     }else{                         element.addclass('x');                         posleft = 0;                     }                     sitenav.stop().animate({                         left: posleft                     });                 });             }         }     } ]); 

    removed check of left position, , moved animation outside if. check if spam filters work :)


    Comments

    Popular posts from this blog

    searchKeyword not working in AngularJS filter -

    sequelize.js - Sequelize: sort by enum cases -

    user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -