0
<style>
 #container { 
 width: 320px; 
 height: 400px;
 border: 1px solid red;
 }
 #top { 
 width: 320px; 
 height: 80px;
 border: 1px solid blue;
 }
</style>
<script type="text/javascript" src="One.js"> </script>
</head>
<body>
<div id="top">
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
<button onclick="pause()">Pause</button>
</div>
<div style="position: relative;" id="container">
 <canvas id="myCanvas" width="320" height="400" 
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="plane" width="320" height="400" 
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="buildings" width="320" height="400" 
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="cloud" width="320" height="400" 
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="buildings2" width="320" height="400" 
 style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="canvas2" width="100" height="100" 
 style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>

So I want to be able to call the start function which will run my canvas animation. My code is fully working when I have the js on the html page. But I can not get it to work when it is as an external script. Thank you

asked Apr 5, 2014 at 10:39
1
  • Is the html file and js file in the same folder..? Commented Apr 5, 2014 at 10:51

1 Answer 1

1

Put the <script type="text/javascript" src="One.js"> </script> right before the </body> tag. That will help. The DOM has to load before you can run your Javascript file, that's why it's wise to put it at the end, when you are sure that everything has been loaded.

answered Apr 5, 2014 at 10:49
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.