[英]How to prevent CSS3 transform from make elements unclickable
Please look at my live code :: 请看我的实时代码::
CSS3 translate: rotate()
makes elements unclickable unless rotations == 0
CSS3
translate: rotate()
rotations == 0
translate: rotate()
使元素不可单击,除非rotations == 0
I'm using the accelorameter to move elements over an axis. 我正在使用加速度计在一个轴上移动元素。 Unfortunatly these elements become unclickable when their rotations isnt at at (0,0,0).
不幸的是,当这些元素的旋转不为(0,0,0)时,它们将变为不可单击。 How do I fix this, so that all elements are clickable at all times?
如何解决此问题,以便所有元素都可随时单击?
<div ng-app="morningharwoodApp" ng-controller="MainCtrl">
<div class="wrap">
<div class="cube">
<div class="icon-wrapper">
<div class="icons" ng-repeat="(key, val) in squares" ng-style="perspective" ng-click="toggle.menu()">
<p>x: {{acceleration.x }}</p>
<p>y: {{acceleration.y}}</p>
<p>z: {{acceleration.z}}</p>
</div>
</div>
</div>
</div>
</div>
CSS: CSS:
html, body, .page-container {
box-sizing: border-box;
height: 100%;
padding:0;
margin:0;
}
*, *:before, *:after {
box-sizing: inherit;
}
.group:after {
content: "";
display: table;
clear: both;
}
.wrap {
position: relative;
width: 100%;
height: 100%;
padding: 3.5%;
font-family: Helvetica, Arial, sans-serif;
}
.cube {
position: relative;
width: 100%;
height: 100%;
background: url(http://placekitten.com/1600/1080);
background-size: cover;
padding: 30px;
@extend .group;
}
.icon-wrapper {
@extend .group;
}
.fill {
@extend .group;
height: 100%;
width: 100%;
position: relative;
top:0;
left:0;
background: #fff;
}
.icons {
padding: 25px;
height: 250px;
width: 250px;
margin: 12px;
color: #fff;
background: black;
float: left;
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
-o-transform: translateZ(0);
transform: translateZ(0);
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
-webkit-transition: -webkit-transform 500ms ease;
-moz-transition: -moz-transform 250ms ease;
-o-transition: -o-transform 250ms ease;
transition: transform 250ms ease;
transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transform-origin: top center;
-moz-transform-origin: top center;
-o-transform-origin: top center;
transform-origin: top center;
-webkit-transform:translateZ(1px);
}
JS: JS:
$scope.navigation = {
status: false
};
$scope.toggle = {
menu: function() {
$scope.navigation.status = !$scope.navigation.status;
console.log($scope.navigation.status);
}
};
$scope.squares = [1,2,3,4,5,6,7,8];
if ($window.DeviceMotionEvent !== undefined) {
$window.ondevicemotion = function(event) {
$scope.acceleration = {
x: Math.min(Math.max(parseInt(event.accelerationIncludingGravity.x*10), -30), 30) | 0,
y: Math.min(Math.max(parseInt(event.accelerationIncludingGravity.y*2), -30), 30) | 0,
z: Math.min(Math.max(parseInt(event.accelerationIncludingGravity.z), -30), 30) | 0
};
$scope.perspective = {
transform: 'perspective(800px) rotateY('+ $scope.acceleration.x +'deg)' + 'rotateX('+ $scope.acceleration.y +'deg)'
// 'rotateX('+ $scope.acceleration.x +'deg)' +'rotateZ('+ $scope.acceleration.z +'deg)'
};
$scope.$digest();
};
}
What I noticed playing around with it is if I rotated a square around the Y axis, the side sticking out towards me would be "clickable," while the side pointed away would not be. 我注意到,如果我绕着Y轴旋转正方形,朝我伸出的那一侧将是“可点击的”,而指向我的那一侧则不会。 Adding "z-index: 1" to one of the container divs (icon-wrapper or cube or wrap) seems to help.
将“ z-index:1”添加到容器div之一(icon-wrapper,cube或wrap)似乎有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.