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:
stop(), need.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
Post a Comment