Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
Make images become unavailable when screen is not on fullscreen

I'm currently making my own card game with JS. The board randomly generates your deck with 5 images and displays them on the screen.

I've tried to make it so when you click on an image, it shows up in the game area, like simulating that you've "chosen that card" to play. With JQuery:

$("#img5").click
( 
    function() 
    { 
        var carta = document.images["img5"].src;
        document.images["carta2"].src = carta;
    } 
);

Ok, but the thing is that I only want that to happen when you are on fullscreen mode, so I made this logic:

pantallaCompleta = false;
contadorScreen = 0;
document.onfullscreenchange = function(event) 
{
    contadorScreen = contadorScreen + 1;
    if(contadorScreen % 2 === 0)
    {
        pantallaCompleta = false;
        console.log("Exiting fullscreen");
        console.log(contadorScreen);
        console.log(pantallaCompleta);
    }
    else
    {
        pantallaCompleta = true;
        console.log("Entering fullscreen");
        console.log(contadorScreen);
        console.log(pantallaCompleta);
    }
};

The logic works so when you load the page, you're not on fullscreen mode so counter equals = 0 and check = false. Then, when document.onfullscreenchange = function(event) happens counter equals counter++ and check changes to true.

Okay, so with all of that combined and working, I try to put the JQuery code inside this:

if(pantallaCompleta == true)

It never works. The console.log(pantallaCompleta); is telling me that the check is true or false with accuracy, but the click on images never works.

Does anyone have an idea of what could be wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Currently you have

if(pantallaCompleta == true) {   
  $("#img5").click(function() {
    var carta = document.images["img5"].src;         
    document.images["carta2"].src = carta;
  });
}

This will only set an event listener on img5 if pantallaCompleta is true when this code runs, which is likely on page load.

I suggest you want an event listener that is always assigned (no matter the state of pantallaCompleta), but checks to see if that value is true or false before changing the img src.

$("#img5").click(function() {
  if(pantallaCompleta == true) {   
    var carta = document.images["img5"].src;         
    document.images["carta2"].src = carta;
  }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda