So... I am working on a horizontal menu with elements that overflow the x-axis of the window. Navigating items in the menu is done with the arrow keys, through an Angular controller.
I am trying to figure out a way to animate a CSS transition, that will make the whole menu shift left / right according to the navigation, so that the active item is always visible. This should be done without scrolling, since the window is set to overflow: hidden.
My first instinct was to use jquery .animate(), but that doesn't work for me inside an angular controller / directive.
HTML for the menu:
<section id="catContainer" cat-navigation ng-class="{'disabled': activeLevelIndex > 1}">
<div ng-repeat="category in categories" ng-class="{'active': $index == activeCatIndex }" class="category selectable">
<img class="catImg" ng-src="{{category.image}}" />
<h2>{{category.name}}</h2>
</div>
</section>
and this is the code that i am triggering when the right/left button is pressed:
var current = $("#catContainer .category.active");
var left = current.position().left;
var right = left + current.width();
var shift;
if (right > $(window).width)
shift = -(1.2 * current.width()) + $("#catContainer").css("left-margin");
else if (left < 0){
shift = (1.2 * current.width()) + $("#catContainer").css("left-margin");
}
$("#catContainer").animate({
"margin-left" : shift
}, 400, function() {
console.log("cat anim done.");
});
$("#catContainer").css("margin-left", shift);
Currently, I get the "cat anim done" logged, but nothing actually happens. Any help with figuring out how to get this animation to work will be much appreciated.