I have a problem with jQuery and javascript code; when I write this jQuery below between </head> and <body>
<script type="text/javascript"> var $j = jQuery.noConflict(); $j(document).ready(function(){ $j('#page_effect').fadeIn(3000); }); </script>
and then write javascript code in body tag
<script src="bubbles.js"></script> <script type="text/javascript"> bubblesMain(new Object({ type : 'linear', minSpeed : 100, maxSpeed : 400, minSize : 30, maxSize : 55, num : 100, colors : new Array('#FF0000','#FFFFFF','#FFCC99', '#FF33CC') })); </script>
then jQuery code may work, but javascript code doesn't work. Finally, I found that when I resize the browser after the first download, it works fine.
bubble.js is to automatically create a canvas element and then creates some bubbles with animations inside the canvas.
partially the code is below:
function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(start,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ var height = parseInt(document.getElementById("canvasBubbles").clientHeight); var width = parseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function start(){ var canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); };
and I have <div id="canvasBubbles"></div> indise html.
Then, after I added the following code to bubbles.js, it will work.
window.onload = function(event) { bubbleResize(); }
I wonder if anyone can suggest a more reasonable solution? thanks.