简体   繁体   English

如何根据用户使用JS的时间将lite模式更改为dark模式?

[英]How can I change the lite mode to dark mode according to the user's time using JS?

How can I change the lite mode to dark mode according to the user's time using JS ?如何根据用户使用 JS 的时间将精简模式更改为暗模式?

// I'm working with jQuery
$(document).ready(function(){
   $('.toggle').click(function(){

    $('body').toggleClass('dark')
       $('.row1').toggleClass('dark')
       $('.row2').toggleClass('dark')
       $('.row3').toggleClass('dark')

i don't have any error我没有任何错误

Something like this, using CSS variables to simplify the js.像这样,使用 CSS 变量来简化 js。

 $(function() { var hour = (new Date).getHours(); if (hour >= 16) { $('.wrapper').removeClass('light').addClass('dark'); } else { $('.wrapper').removeClass('dark').addClass('light'); } console.log(hour); });
 html, body { height: 100%; } .light { --main-bg-color: #eee; --main-tx-color: #000; } .dark { --main-bg-color: #222; --main-tx-color: #555; } .wrapper { width: 100%; height: 100%; background: var(--main-bg-color); } h2 { color: var(--main-tx-color); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="wrapper light"> <h2>SOMETHING HERE</h2> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据用户的时间将精简模式更改为深色模式? - How can I change the lite mode to dark mode according to the user's time? 如何使用 div 和 JS 在暗/亮模式之间切换? - How can I toggle between dark/light mode using a div & JS? 我可以使用 JavaScript 切换暗模式吗? - Can I toggle dark mode using JavaScript? 如何在浏览器中保存暗模式值(使用jquery) - How can i save the dark mode value in browsers ( using jquery ) 如何保存 cookies 以进行暗模式和亮模式切换? - How can I save cookies for dark mode and light mode toggling? 当用户在 React Native Android 中设置暗模式时,如何更改 ScrollView 滚动条的颜色? - How to change the colour of a ScrollView's scrollbar when the user has set dark mode on in React Native Android? 如何在使用 header 作为开关位置的同时将我的亮/暗模式主题包裹在 index.js 周围? - How can I wrap my light/dark mode theme around index.js while using my header as the switch location? 如何更改 state 以使我的切换按钮更改为暗模式? - How can i change the state for my toggle button to change to dark mode? 在暗模式下更改图像 - Change image in dark mode 如何强制谷歌地图到精简模式(没有WebGL) - How can I force Google Map to Lite Mode (no WebGL)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM