Code Monkey home page Code Monkey logo

Comments (3)

Atinux avatar Atinux commented on July 22, 2024

Cannot you apply the transition using CSS directly?

from color-mode.

ImpossibleReality avatar ImpossibleReality commented on July 22, 2024

Let me clarify what I want to do. I currently have something like this in my global css:

* {
  transition: background-color 0.5s;
}
.preload * {
  transition: none !important;
}

The preload class is given to <body> on ssr, then removed after the client mounts.

This isn't really ideal, since if I don't want an element to have a background transition then I have to explicitly specify that, or if I want an element to have a transition when the page is mounting (ie a loader/transition) then I have to override the !important, which soon becomes a mess.

It would be nice if I could apply a transition class to <body> only when the color mode changes and remove it after the transition is finished.

A way I could do this is by applying the class when someone clicks on the button to change the scheme, but then you don't get a transition when the color mode is system, and the user changes their default color mode.

from color-mode.

Atinux avatar Atinux commented on July 22, 2024

I am using a transition for the example and does not have any issue:

https://codesandbox.io/s/github/nuxt-community/color-mode-module?file=/example/assets/main.css:657-693

You can create a plugin colorMode.client.js and use $colorMode.watch if you want advanced usage:

export default function ({ $colorMode }) {
  $colorMode.$watch("value", (c) => {
    console.log("$colorMode.value is", c);
  });
}

from color-mode.

Related Issues (20)

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.