I'm trying to create a CSS animation to move the clicked button (actually, the whole DIV that it's contained in) to the center. Each button is in a Div and I'm having trouble figuring out how, using one css class, to get any of the buttons to move to the center.
I've tried a variety of ways in the css, but haven't been able to do it where the other buttons don't move.
A codepen is here.
If you run the code and click the "DIV0" button, it moves to the center. (Click the button again to reset.) When you click any of the other buttons, I want them to go to the same spot as where the "DIV0" button went.
Update: I need to set up the DIVs/Buttons programmatically (passing the "divs" array to the HTML so that ng-repeat builds the layout). The size of the "divs" array may vary, so doing this method automates the building of the layout. Also, the div needs to take up 50% of the width and height so that it arrays out a 2-divs-across matrix on the screen. And each div will be fully filled with an image and text. I'm trying to move the full contents of the div to the center, not just the button.
so my layout may look like:
DIV0 DIV1
DIV2 DIV3
or just:
DIV0 DIV1
DIV2
Here is another codepen. http://codepen.io/furnaceX/pen/BKjyEp/ This one gets all the buttons to the right location, but the centering won't animate. Any ideas?
angular.module('myApp', [])
.controller("ctrl", ['$scope', function($scope) {
$scope.divs = [{id: 0, center: false}, {id: 1, center: false},
{id: 2, center: false}, {id: 3, center: false}];
$scope.fade = false;
$scope.go = function(div) {
if (!$scope.fade) {
div.center = true;
console.log("click again to reset");
$scope.fade = true;
} else {
div.center = false;
$scope.fade = false;
}
}
}])
html, body {
height: 100%;
width: 100%;
}
.block {
text-align: center;
width: 50%;
height: 50%;
float: left;
}
.center {
transition:0.5s linear all;
transform: translate(50%,50%);
top: 50%;
left: 50%;
//position: relative;
}
.fadeout {
transition:0.5s linear all;
opacity: 0 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div class="container" ng-controller="ctrl">
<div ng-repeat="div in divs" class="block">
<div ng-class="{center: div.center, fadeout: fade*!div.center}">
<button ng-click="go(div)">DIV{{ div.id }}</button>
</div>
</div>
</div>
</div>