I am writing a ASP.NET page that load 3 arrays of data (X,Y,Z axis) and show them in a 3D animation and a 2D Line Chart.
For this I use ThreeJS and Google Chart.
My page is opened as an IFrame from a parent page. Everything works fine everytime on Chrome. In both IE and Firefox, the first time works well but if I close and then reopen the IFrame, my page is not loaded correctly: DIVs are not positioned in the correct way and the 3D animation is rendered but does not rotate.
I placed a "reset button" in order to test if the problem is in the code or something happens during loading.
My "reset button" works! In fact, after clicking, everything is in the wright place and animation rotate.
I searched a lot and I saw some "conflict" or similar between document.ready() and google.load function... I tried almost anything but still not work...
Here some code to better explain:
<head>
[...]
<script type="text/javascript" src="../Js/three.min.js"></script>
<script type="text/javascript" src="../Js/TrackballControls.js"></script>
<script type="text/javascript" src="../Js/font/helvetiker_regular.typeface.js"></script>
<script type="text/javascript" src="../Js/jquery-1.js"></script>
<script type="text/javascript" src="../Js/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("visualization", "1", { packages: ["corechart"] }); </script>
[...]
<script type="text/javascript">
$(document).ready(function () {
//here I initialize my 3D object
resetPositions();
});
function resetPositions() {
$('#graph2DLineChart').css('position', 'absolute');
$('#graph2DLineChart').css('top', '253px');
$('#graph2DLineChart').css('left', '652px');
$('#graph2DLineChart').css('background-color', '#ffffff');
$('#graph2DLineChart').css('color', '#000000');
$('#graph2DLineChart').css('width', '280px');
$('#graph2DLineChart').css('height', '300px');
$('#graph2DLineChart').css('z-index', '50');
$('#graph3DContainer').css('position', 'relative');
$('#graph3DContainer').css('top', '0px');
$('#graph3DContainer').css('left', '0px');
$('#graph3DContainer').css('background-color', '#333F47');
$('#graph3DContainer').css('color', '#ffffff');
$('#graph3DContainer').css('width', '906px');
$('#graph3DContainer').css('height', '670px');
$('#graph3DContainer').css('z-index', '1');
WIDTH = 906;
HEIGHT = 670;
camera.aspect = WIDTH / HEIGHT;
camera.updateProjectionMatrix();
renderer.setSize(WIDTH, HEIGHT);
controls.handleResize();
drawChart();
}
[...]
</script>
</head>
<body>
[...]
<input type="button" id="resetButton" class="btncontrol" value="Reset positions" onclick="resetPositions();" />
At least, I've tried also this document.ready solutions:
$(document).ready(function () {
//here I initialize my 3D object
setTimeout(function () {
resetPositions();
}, 1000);
});
This solutions works everytime!!!! but I really HATE IT... please is there a different way to make sure a page will be fully loaded ???
Many many thanks!