First example of Three.js doesn't work

I'm about to learn `three.js`. I've downloaded the `library` from github: [**three.js**][1]

I tried to run the first example of three.js in the link above. The weird problem is, it's working in jsFiddle but it not working in my computer.

I've this error in console: TypeError: document.body is null [Break On This Error] document.body.appendChild( renderer.domElement );
**[jsFiddle Live Working Demo][2]**

And here is my code exactly copied from link above:
*And yes the three.js included in the page.* var camera, scene, renderer; var geometry, material, mesh; init(); animate(); function init() { camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 ); camera.position.z = 1000; scene = new THREE.Scene(); geometry = new THREE.CubeGeometry( 200, 200, 200 ); material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } ); mesh = new THREE.Mesh( geometry, material ); scene.add( mesh ); renderer = new THREE.CanvasRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); } function animate() { // note: three.js includes requestAnimationFrame shim requestAnimationFrame( animate ); mesh.rotation.x += 0.01; mesh.rotation.y += 0.02; renderer.render( scene, camera ); } [1]: https://github.com/mrdoob/three.js/ [2]: http://jsfiddle.net/BlackSRC/XWCRM/1/

以上就是First example of Three.js doesn't work的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏