Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

BrunoHSL

Fazer apagar imagem anterior

Recommended Posts

E ai galera, seguinte estou fazendo um projeto e preciso da ajuda de vocês rs, coloquei uma imagem numa determinada variável e a cada clique no teclado ele movimenta 50px dependendo da onde ele quer movimentar, ele movimenta como quero porém fica ele fica um "rastro" na onde passa, e quero que apague o elemento anterior, afim de dar uma sensação meio de movimento, vou publicar o código aqui e ficaria muito agradecido se pudessem me ajudar, obs : o codigo deve ser feito todo em Javascript... Obrigado desde já.

<html>
    <head>
        <meta charset='utf-8'>
        <script>
		var i, j;
		var m = [];
		var x=0; var y=0;
		var canvas;
        var ctx;
		var imagem = new Image();
		imagem.src = "link da imagem 2";
		var x = 202;
		var y = 352;
		
	
	 
		
		function fase1()
	{
	
		 canvas = document.getElementById("canvas");
         ctx = canvas.getContext("2d");
		 
		
	    tabela();
		
		ctx.drawImage(m[7][1],102,102);
		player();
		
    }
	
	
	function tabela()
	
	{
	
	canvas = document.getElementById("canvas");
    ctx = canvas.getContext("2d");
	
	
	
	  for (i=0;i<9;i++)
		  {
		   m[i]=[];
		  }
		for(i=0;i<9;i++)
		{
		 for(j=0;j<9;j++)
		 {
		   m[0][0]=ctx.fillStyle="gray";
		   ctx.fillRect(0,0,50,50);
		   m[0][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(50,0,50,50);
		   m[0][2]=ctx.fillStyle="gray";
		   ctx.fillRect(100,0,50,50);
		   m[0][3]=ctx.fillStyle="lightgray";
		   ctx.fillRect(150,0,50,50);
		   m[0][4]=ctx.fillStyle="gray";
		   ctx.fillRect(200,0,50,50);
		   m[0][5]=ctx.fillStyle="lightgray";
		   ctx.fillRect(250,0,50,50);
		   m[0][6]=ctx.fillStyle="gray";
		   ctx.fillRect(300,0,50,50);
		   m[0][7]=ctx.fillStyle="lightgray";
		   ctx.fillRect(350,0,50,50);
		   m[0][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(0,50,50,50);
		   m[1][0]=ctx.fillStyle="gray";
		   ctx.fillRect(50,50,50,50);
		   m[1][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(100,50,50,50);
		   m[1][2]=ctx.fillStyle="gray";
		   ctx.fillRect(150,50,50,50);
		   m[1][3]=ctx.fillStyle="lightgray";
		   ctx.fillRect(200,50,50,50);
		   m[1][4]=ctx.fillStyle="gray";
		   ctx.fillRect(250,50,50,50);
		   m[1][5]=ctx.fillStyle="lightgray";
		   ctx.fillRect(300,50,50,50);
		   m[1][6]=ctx.fillStyle="gray";
		   ctx.fillRect(350,50,50,50);
		   m[1][7]=ctx.fillStyle="gray";
		   ctx.fillRect(0,100,50,50);
		   m[1][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(50,100,50,50);
		   m[2][0]=ctx.fillStyle="gray";
		   ctx.fillRect(100,100,50,50);
		   m[2][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(150,100,50,50);
		   m[2][2]=ctx.fillStyle="gray";
		   ctx.fillRect(200,100,50,50);
		   m[2][3]=ctx.fillStyle="lightgray";
		   ctx.fillRect(250,100,50,50);
		   m[2][4]=ctx.fillStyle="gray";
		   ctx.fillRect(300,100,50,50);
		   m[2][5]=ctx.fillStyle="lightgray";
		   ctx.fillRect(350,100,50,50);
		   m[2][6]=ctx.fillStyle="lightgray";
		   ctx.fillRect(0,150,50,50);
		   m[2][7]=ctx.fillStyle="gray";
		   ctx.fillRect(50,150,50,50);
		   m[2][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(100,150,50,50);
		   m[3][0]=ctx.fillStyle="gray";
		   ctx.fillRect(150,150,50,50);
		   m[3][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(200,150,50,50);
		   m[3][2]=ctx.fillStyle="gray";
		   ctx.fillRect(250,150,50,50);
		   m[3][3]=ctx.fillStyle="lightgray";
		   ctx.fillRect(300,150,50,50);
		   m[3][4]=ctx.fillStyle="gray";
		   ctx.fillRect(350,150,50,50);
		   m[3][5]=ctx.fillStyle="gray";
		   ctx.fillRect(0,200,50,50);
		   m[3][6]=ctx.fillStyle="lightgray";
		   ctx.fillRect(50,200,50,50);
		   m[3][7]=ctx.fillStyle="gray";
		   ctx.fillRect(100,200,50,50);
		   m[3][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(150,200,50,50);
		   m[4][0]=ctx.fillStyle="gray";
		   ctx.fillRect(200,200,50,50);
		   m[4][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(250,200,50,50);
		   m[4][2]=ctx.fillStyle="gray";
		   ctx.fillRect(300,200,50,50);
		   m[4][3]=ctx.fillStyle="lightgray";
		   ctx.fillRect(350,200,50,50);
		   m[4][4]=ctx.fillStyle="lightgray";
		   ctx.fillRect(0,250,50,50);
		   m[4][5]=ctx.fillStyle="gray";
		   ctx.fillRect(50,250,50,50);
		   m[4][6]=ctx.fillStyle="lightgray";
		   ctx.fillRect(100,250,50,50);
		   m[4][7]=ctx.fillStyle="gray";
		   ctx.fillRect(150,250,50,50);
		   m[4][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(200,250,50,50);
		   m[5][0]=ctx.fillStyle="gray";
		   ctx.fillRect(250,250,50,50);
		   m[5][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(300,250,50,50);
		   m[5][2]=ctx.fillStyle="gray";
		   ctx.fillRect(350,250,50,50);
		   m[5][3]=ctx.fillStyle="gray";
		   ctx.fillRect(0,300,50,50);
		   m[5][4]=ctx.fillStyle="lightgray";
		   ctx.fillRect(50,300,50,50);
		   m[5][5]=ctx.fillStyle="gray";
		   ctx.fillRect(100,300,50,50);
		   m[5][6]=ctx.fillStyle="lightgray";
		   ctx.fillRect(150,300,50,50);
		   m[5][7]=ctx.fillStyle="gray";
		   ctx.fillRect(200,300,50,50);
		   m[5][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(250,300,50,50);
		   m[6][0]=ctx.fillStyle="gray";
		   ctx.fillRect(300,300,50,50);
		   m[6][1]=ctx.fillStyle="lightgray";
		   ctx.fillRect(350,300,50,50);
		   m[6][2]=ctx.fillStyle="lightgray";
		   ctx.fillRect(0,350,50,50);
		   m[6][3]=ctx.fillStyle="gray";
		   ctx.fillRect(50,350,50,50);
		   m[6][4]=ctx.fillStyle="lightgray";
		   ctx.fillRect(100,350,50,50);
		   m[6][5]=ctx.fillStyle="gray";
		   ctx.fillRect(150,350,50,50);
		   m[6][6]=ctx.fillStyle="lightgray";
		   ctx.fillRect(200,350,50,50);
		   m[6][7]=ctx.fillStyle="gray";
		   ctx.fillRect(250,350,50,50);
		   m[6][8]=ctx.fillStyle="lightgray";
		   ctx.fillRect(300,350,50,50);
		   m[7][0]=ctx.fillStyle="gray";
		   ctx.fillRect(350,350,50,50);
		   m[7][1]=document.getElementById("i1");
		   
		   
         }
		} 
	}
	
	function player(){  
	  
imagem.onload = function(){
    ctx.drawImage(imagem, x, y, imagem.width, imagem.height);
}
document.onkeydown = function(event) {
		
    switch(event.which) {
	     
        case 37: //pra esquerda
            x = x - 50;
        break;
        case 38: //pra cima
            y = y - 50;
        break;
        case 39: //pra direita
            x = x + 50;
        break;
        case 40: //pra baixo
            y = y + 50;
        break;
    }
}
setInterval(function(){
    ctx.drawImage(imagem, x, y, imagem.width, imagem.height);
}, 50);
	 }
	 
	 
	 
	 
 

	
	 
	
	
	
        </script>
    </head>
   <body onload="fase1()">
   <canvas id="canvas" width="400" height="400" style="border: solid 0px black; margin: 0px auto; display: block;">
   
   <img src="link da imagem 1" id="i1">
   
   
   
   
   </canvas>
    </body>
</html>

A imagem 1, só deixei ele numa determinada coordenada, pois vou mexer nela depois.

Compartilhar este post


Link para o post
Compartilhar em outros sites

  • Conteúdo Similar

    • Por ILR master
      Fala pessoal.

      Não estou conseguindo converter .jpg para .webp
       
      Alguém pode me ajudar? Segue código abaixo:
       
      $fotob = 'imagem.jpg'; $foto = explode('.',$fotob); $f = $foto[0]; $forigem = $fotob; $origem = 'fotos_noticias/'.$forigem; $fdestino = $f.'.webp'; $destino = 'fotos_capa/'.$fdestino; $imagem = imagecreatefromjpeg($origem); $imgX = imagesx($imagem); $imgY = imagesy($imagem); $novaImagem = imagecreatetruecolor($imgX, $imgY); imagealphablending($novaImagem, false); imagesavealpha($novaImagem, true); imagecopyresampled($novaImagem, $imagem, 0, 0, 0, 0, $imgX, $imgY, $imgX, $imgY); imagewebp($novaImagem, $destino, 100); imagedestroy($imagem); // Importante para limpar o cache
    • Por luiz monteiro
      Olá.
      Estou atualizando meu conhecimento com Front-End e me deparei com o seguinte problema.
      Criei um sistema para fazer o upload de imagens e alguns campos text.
      Algo bem simples para depois começar a estudar javascript para mostrar a miniatura....
      Mas quando saio do navegador Chrome ou da aba por mais de 3 minutos, ao retornar o navegador as vezes atualiza ou nem chega atualizar mas limpa os campos.
      Estou usando um Smart Motorola com Android, mas um amigo testou no iPhone e acontece a mesma coisa.
      Gostaria de saber se há como usar javascript para evitar isso?
      Agradeço desde já.

      <!DOCTYPE html>
      <html>
      <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <title>Uploader</title>
      </head>
      <body>
          <form action="?" method="post" enctype="multipart/form-data">
              <br><br>
              <div>selecione a imagem 1</div>
              <input type="file" name="foto1" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem1">
              
              <br><br>
              <input type="file" name="foto2" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem2">
              
              <br><br>

              <input type="file" name="foto3" accept="image/*">
              <br><br>
              <input type="text" name="nome_imagem3">
              
              <br><br>
              <input type="submit" value="Enviar">
              <br><br>
          </form>
      <?php
      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
          vardump ($_FILES);
      }
      ?>
      </body>
      </html>
       
       
       
    • Por belann
      Olá!
       
      Estou usando o nextjs versão 15.2.3 e criei uma navbar que quando é carregado o programa aparece com a home, mas na hora de clicar na página produtos desaparece a navbar.
      A navbar esta sendo chamada no layout.tsx estou usando typescript
      e fica dessa forma
      <div>           <Navbar/>             <main>{children}</main>             </div>  
    • Por violin101
      Caros amigos, saudações.

      Estou com uma dúvida, referente cálculo de valores em tempo real.

      Tenho uma rotina, que faz o cálculo, o problema é mostrar o resultado.

      Quero mostrar o RESULTADO assim: 0,00  ou  0.00

      Abaixo posto o código.
      jQuery('input').on('keyup',function(){ //Remover ponto e trocar a virgula por ponto var m = document.getElementById("pgRest").value; while (m.indexOf(".") >= 0) { m = m.replace(".", ""); } m = m.replace(",","."); //Remover ponto e trocar a virgula por ponto var j = document.getElementById("pgDsct").value; while (j.indexOf(".") >= 0) { j = j.replace(".", ""); } j = j.replace(",","."); m = parseFloat(jQuery('#pgRest').val() != '' ? jQuery('#pgRest').val() : 0); j = parseFloat(jQuery('#pgDsct').val() != '' ? jQuery('#pgDsct').val() : 0); //Mostra o Resultado em Tempo Real jQuery('#pgTroco').val(m - j); <<=== aqui estou errando })  
       
      Grato,
       
      Cesar
       
       
    • Por violin101
      Caro amigos, saudações.

      Tenho uma tabela escrita em JS que funciona corretamente.
       
      Minha dúvida:
      - como devo fazer para quando a Tabela HTML estiver vazia, exibir o LOGO da Empresa ?

      Abaixo posto o script:
      document.addEventListener( 'keydown', evt => { if (!evt.ctrlKey || evt.key !== 'i' ) return;// Não é Ctrl+A, portanto interrompemos o script evt.preventDefault(); //Chama a Função Calcular Qtde X Valor Venda calcvda(); var idProdutos = document.getElementById("idProdutos").value; var descricao = document.getElementById("descricao").value; var prd_unid = document.getElementById("prd_unid").value; var estoque_atual = document.getElementById("estoque_atual").value; var qtde = document.getElementById("qtde").value; var vlrunit = document.getElementById("vlrunit").value; var vlrtotals = document.getElementById("vlrtotal").value; var vlrtotal = vlrtotals.toLocaleString('pt-br', {minimumFractionDigits: 2}); if(validarConsumo(estoque_atual)){ //Chama a Modal com Alerta. $("#modal_qtdemaior").modal(); } else { if(qtde == "" || vlrunit == "" || vlrtotal == ""){ //Chama a Modal com Alerta. $("#modal_quantidade").modal(); } else { //Monta a Tabela com os Itens html = "<tr style='font-size:13px;'>"; html += "<td width='10%' height='10' style='text-align:center;'>"+ "<input type='hidden' name='id_prds[]' value='"+idProdutos+"'>"+idProdutos+"</td>"; html += "<td width='47%' height='10'>"+ "<input type='hidden' name='descricao[]' value='"+descricao+"'>"+descricao+ "<input type='hidden' name='esp[]' value='"+prd_unid+"'> - ESP:"+prd_unid+ "<input type='hidden' name='estoq[]' value='"+estoque_atual+"'></td>"; html += "<td width='10%' height='10' style='text-align:center;'>"+ "<input type='hidden' name='qtde[]' value='"+qtde+"'>"+qtde+"</td>"; html += "<td width='12%' height='10' style='text-align:right;'>"+ "<input type='hidden' name='vlrunit[]' value='"+vlrunit+"'>"+vlrunit+"</td>"; html += "<td width='14%' height='10' style='text-align:right;'>"+ "<input type='hidden' name='vlrtotal[]' value='"+vlrtotal+"'>"+vlrtotal+"</td>"; html += "<td width='12%' height='10' style='text-align:center;'>"+ "<button type='button' class='btn btn-uvas btn-remove-produto' style='margin-right:1%; padding:1px 3px; font-size:12px;' title='Remover Item da Lista'>"+ "<span class='fa fa-minus' style='font-size:12px;'></span></button></td>"; html += "</tr>"; $("#tbventas tbody").append(html); //Função para Somar os Itens do Lançamento somar(); $("#idProdutos").val(null); $("#descricao").val(null); $("#prd_unid").val(null); $("#qtde").val(null); $("#vlrunit").val(null); $("#vlrtotal").val(null); $("#idProdutos").focus(); //Se INCLUIR NOVO produto - Limpa a Forma de Pagamento $("#pgSoma").val(null); $("#pgRest").val(null); $("#pgDsct").val(null); $("#pgTroco").val(null); $("#tbpagar tbody").empty(); }//Fim do IF-qtde }//Fim do Validar Consumo });//Fim da Função btn-agregar  
      Grato,

      Cesar
       
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.