Surfaces created with Famo.us/Angular and translated to a negative Z position don't receive ng-click
events in Chrome. This seems to be a known WebKit bug and is not a problem in Firefox; see an example in the below Plunker.
Now I would like to have a collection of surfaces floating in and out along the Z-axis and be able to click on any of them to bring it to the foreground, which is a problem in Chrome when they have a somewhat large negative Z value.
I could have the surfaces fa-pipe-to
an EventHandler, but the event data doesn't seem to contain information about the source of the event, so I'm not able to discern exactly what surface was clicked.
What is a good way to implement this behaviour that plays well in Chrome?
The Famo.us Periodic Table Demo implements a behaviour similar to what I have in mind: Surfaces float there in and out and it works well in Chrome. How is it done there? ...haven't been able to figure that out from the minified code.
The Unity game engine provides a raycasting functionality, where you can get objects hit under a mouse click. Maybe I should implement something similar, but my guess is that picking surfaces in the Periodic Table Demo is done in a simpler way. Did they maybe just make sure that the surfaces stay in positive Z locations?
Here's an example rendering a red square at Z=0, which receives a click event in Chrome, while the green square rendered at Z=-200 won't get a click event, unless you'll run the example in Firefox:
http://plnkr.co/edit/UZp4oB?p=preview
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Clicking on Famo.us surfaces in deep z-space</title>
<link href="famous-angular.css" rel="stylesheet" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
<script src="https://code.famo.us/famous/global/0.2.2/famous.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="famous-angular.js"></script>
</head>
<body ng-app="faScrollViewExampleApp">
<fa-app ng-controller="ScrollCtrl" fa-perspective="1000">
<fa-view ng-repeat="surface in surfaces">
<fa-modifier fa-size="[200, 200]"
fa-translate="[200*$index, 200*$index, surface.zIndex]">
<fa-surface fa-background-color="surface.color"
ng-click="surfaceClick($index)">
I'm in z = {{surface.zIndex}}
</fa-surface>
</fa-modifier>
</fa-view>
</fa-app>
<script>
angular.module('faScrollViewExampleApp', ['famous.angular'])
.controller('ScrollCtrl', ['$scope', '$famous', function($scope, $famous) {
$scope.surfaces = [
{color: 'red', zIndex: 0},
{color: 'green', zIndex: -200} ];
$scope.surfaceClick = function( index ) {
alert( "index " + index + " clicked");
}
}]);
</script>
</body>
</html>