I am trying to position the box azul
depending on the box I hit click
, that is, if I hit click
the green box, the blue box must go down to where the green box is, it cannot be on top, it must be as if I placed the property top: 500px;
of css
or something like that.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.showFuncion = function() {
$scope.showDiv = true;
$scope.fafa = !$scope.fafa
}
});
</script>
<body ng-app="myApp" ng-controller="myCtrl">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<div style="height: 150px; background-color: red;" ng-click="showFuncion()">
ESTE ES EL LADO DERECHO DE LA PANTALLA
</div>
<div style="height: 150px; background-color: yellow;" ng-click="showFuncion()">
ESTE ES EL LADO DERECHO DE LA PANTALLA
</div>
<div style="height: 150px; background-color: green;" ng-click="showFuncion()">
ESTE ES EL LADO DERECHO DE LA PANTALLA
</div>
<div style="height: 150px; background-color: pink;" ng-click="showFuncion()">
ESTE ES EL LADO DERECHO DE LA PANTALLA
</div>
<div style="height: 150px; background-color: black;" ng-click="showFuncion()">
ESTE ES EL LADO DERECHO DE LA PANTALLA
</div>
</div>
<div class="col-sm-6 col-md-6 col-xs-6" ng-cloak ng-if="showDiv && fafa">
<div style="height: 150px; background-color: blue;">
ESTE ES EL LADO IZQUEIRDO DE LA PANTALLA
</div>
</div>
</div>
</div>
</body>
</html>
This is the error offsetTop
that shows me in 0
I have made the following changes to your code:
$event
as a parameter in the functions that are called from theng-click
. This is so that we can then read the element that was clicked on.ng-style
(with value "myStyle") and in the CSS styles I have put a relative position (so that when changing thetop
it moves.$event.currentTarget
) and see in what position from above it is located (withoffsetTop
).miEstilo
to specify the value oftop
to as many pixels as the clicked element is.The code looks like this: