Git Product home page Git Product logo

Comments (1)

neovov avatar neovov commented on August 15, 2024

Hi,

Thanks for the kind words.

The short answer will be: no.

Here is some reasons:

  • I think trying to mess the CSS using JavaScript is a bad practice and should be avoided ;
  • If you still consider doing this, the first solution is to create a new CSS rule based on the :fullscreen rule(s) present in your CSS (for instance, reading #interesting:fullscreen rule and add a #interesting:-webkit-full-screen rule with the same cssText). Unfortunately, browsers don't bother with invalid rules and don't create a CSSRule instance (you can try adding a #interesting:fullscreen rule and try to read it using document.styleSheets[0].cssRules, it won't appear). So, this solution is a dead end.
  • Second solution, read the CSS using window.getComputedStyle. This method is inefficient since you have to provide an element where to read the styles. In other words, with this solution you can only handle the :fullscreen pseudo-selector on the element going fullscreen ; there is some cases where your selector won't be directly on this element.

So, you still have to add the three CSS rules:

#interesting:-webkit-full-screen { background: red; }
   #interesting:-moz-full-screen { background: red; }
         #interesting:fullscreen { background: red; }

Note that you cannot group these selectors due to browser limitation.

An alternative will be to listen for the fullscreenchange event:

document.addEventListener("fullscreenchange", function() {
    document.body.classList.toggle("fullscreen");
}, false);

And the associated CSS:

.fullscreen #interesting { background: green; }

from fullscreen-api-polyfill.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.