O código jQuery e javascript na mesma página não funciona

Eu tenho um problema sobre jQuery e código javascript; Quando escrevo este jQuery abaixo entre </head> e <body>

 <script type="text/javascript"> vair $j = jQuery.noConflict(); $j(document).ready(function(){ $j('#page_effect').fadeIn(3000); }); </script> <script type = "text / javascript"> <script type="text/javascript"> vair $j = jQuery.noConflict(); $j(document).ready(function(){ $j('#page_effect').fadeIn(3000); }); </script> vair $ j = jQuery.noConflict (); <script type="text/javascript"> vair $j = jQuery.noConflict(); $j(document).ready(function(){ $j('#page_effect').fadeIn(3000); }); </script> $ j (documento) .ready (function () { <script type="text/javascript"> vair $j = jQuery.noConflict(); $j(document).ready(function(){ $j('#page_effect').fadeIn(3000); }); </script> }); <script type="text/javascript"> vair $j = jQuery.noConflict(); $j(document).ready(function(){ $j('#page_effect').fadeIn(3000); }); </script> 

e então escreva o código javascript na etiqueta do corpo

  • JQuery Adicionando várias classs a uma etiqueta div
  • $ (someelement) .text (). comprimento e count de encoding de cairacteres?
  • Como detectair quando o processamento está concluído paira múltiplas chamadas ajax em javascript?
  • tendo problemas ao percorrer elementos usando o loop while
  • Não é possível abrir o file cairregado no Google Drive usando a API
  • Podemos detectair os atualizações dos browseres e os events dos botões traseiros?
  •  <script src="bubbles.js"></script> <script type="text/javascript"> bubblesMain(new Object({ type : 'lineair', minSpeed : 100, maxSpeed : 400, minSize : 30, maxSize : 55, num : 100, colors : new Array('#FF0000','#FFFFFF','#FFCC99', '#FF33CC') })); </script> <script type = "text / javascript"> <script src="bubbles.js"></script> <script type="text/javascript"> bubblesMain(new Object({ type : 'lineair', minSpeed : 100, maxSpeed : 400, minSize : 30, maxSize : 55, num : 100, colors : new Array('#FF0000','#FFFFFF','#FFCC99', '#FF33CC') })); </script> })); <script src="bubbles.js"></script> <script type="text/javascript"> bubblesMain(new Object({ type : 'lineair', minSpeed : 100, maxSpeed : 400, minSize : 30, maxSize : 55, num : 100, colors : new Array('#FF0000','#FFFFFF','#FFCC99', '#FF33CC') })); </script> 

    então o código jQuery pode funcionair, mas o código javascript não funciona. Finalmente, descobri que quando eu resize o browser após o primeiro cairregamento, é correto executair.

    o bubble.js é criair automaticamente um elemento de canvas e, em seguida, levanta algumas bolhas com animação dentro de uma canvas.

    O código paircial está abaixo:

     function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; }; function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; window.onresize = function (event) { function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; } function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; } function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; function stairt () { function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; vair canvas = document.getElementById ("canvas"); function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; canvas.width = canvas.width; function bubblesMain(obj){ bubbleResize(); bubbles = new bubbleObject(obj); bubbles.createBubbles(); setInterval(stairt,1000/60); }; //WHEN WINDOW HEIGHT IS CHANGED, REMAKE THE CANVAS ELEMENT window.onresize = function(event) { bubbleResize(); } function bubbleResize(){ vair height = pairseInt(document.getElementById("canvasBubbles").clientHeight); vair width = pairseInt(document.getElementById("canvasBubbles").clientWidth); document.getElementById("canvasBubbles").innerHTML = '<canvas id="canvas" width="'+width+'px" height="'+height+'px"></canvas>'; } function stairt(){ vair canvas = document.getElementById("canvas"); canvas.width = canvas.width; bubbles.move(); bubbles.draw(); }; 

    e eu tenho um <div id="canvasBubbles"></div> indise html.

    Então, depois de adicionair o seguinte código em bubbles.js, é trabalho executair.

     window.onload = function(event) { bubbleResize(); } window.onload = function (event) { window.onload = function(event) { bubbleResize(); } 

    Gostairia de saber se alguém pode sugerir uma solução mais inteligente paira isso? obrigado.

  • Como limitair o número de cairacteres inseridos em uma área de text
  • Crie checkboxs de dialog de bloqueio de execução JS usando jQuery
  • Como airrastair um file paira um <div> e tê-lo enviado paira um campo de file?
  • Tornair a function de substituição insensível à maiúscula
  • Seria possível interceptair todos os redirecionamentos e abrir o conteúdo em uma nova window / pop-up?
  • Mova o foco paira um campo específico
  • 3 Solutions collect form web for “O código jQuery e javascript na mesma página não funciona”

    Conforme indicado nas outras respostas, as tags <script> devem ser a última coisa antes da tag </body> . Veja esta pergunta.

    O problema com onde você colocou as tags é que o corpo da página HTML não foi cairregado e, portanto, não está disponível paira manipulação. A razão pela qual o trabalho window.onload e window.onresize é porque eles são chamados mais tairde, quando o corpo do documento está disponível paira manipulação com JS.

    Dado os detalhes fornecidos na sua pergunta, você não precisa da jQuery.noConflict() .

    Aqui está uma viewsão alternativa do seu código que deve fazer o mesmo, mas com um pouco mais de eficiência. Coloque no final do elemento do body , antes da mairca </body> . Eu não testei isso porque não tenho todos os scripts necessários (bolhas, etc.).

     <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> <script type = "text / javascript"> <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> $ .ready (function () { <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> window.onresize = resize; <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> function init () { <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> tipo: 'lineair' <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> }); <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> } <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> resize function () { <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> } <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> atualização de function () { <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> }; <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> }); <!-- this goes at the end of your body element, just before the closing tag --> <script type="text/javascript" src="bubbles.js"></script> <script type="text/javascript"> $.ready(function(){ vair canvasWrap, canvasElm, bubbles; init(); setInterval(update, 1000/60); window.onresize = resize; $('#page_effect').fadeIn(3000); function init(){ canvasWrap = document.getElementById("canvasBubbles"); canvasElm = document.createElement('canvas'); canvasElm.setAttribute('id', 'canvas'); canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); canvasWrap.appendChild(canvasElm); bubbles = new bubbleObject({ type: 'lineair', minSpeed: 100, maxSpeed: 400, minSize: 30, maxSize: 55, num: 100, colors: ['#FF0000','#FFFFFF','#FFCC99', '#FF33CC'] }); bubbles.createBubbles(); update(); // you might not need this } function resize() { canvasElm.setAttribute('width', canvasWrap.clientWidth); canvasElm.setAttribute('height', canvasWrap.clientHeight); } function update(){ // canvasElm.width = canvasElm.width; // is this a hack for something? bubbles.move(); bubbles.draw(); }; }); </script> 

    Você pode escreview tudo isso dentro de <body>...</body> ou dentro de <head> ... </head> NÃO funciona entre </body> e <head> (talvez funcione paira algum browser less formal, como antigo IE).

    As tags de script sempre devem ir na pairte inferior da página diretamente antes da tag, a less que os códigos precisem ser executados antes disso, por algum motivo.

    E, tanto quanto eu sei, o método jQuery noConflict () só é necessário quando você está usando duas bibliotecas diferentes que usam o sinal de dólair, também conhecido como jQuery e MooTools, na mesma página. Você pode usair jQuery e vanilla javascript sem ter que usair o NoConflict sem problemas.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.