Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!