hexo博客添加暗色模式_我如何向網站添加暗模式

hexo博客添加暗色模式

同一個網站,兩種不同的配色方案 (Same website, two different color schemes)

Last year I made it a point to redesign my website from scratch. I wanted something simple and minimalist looking that clearly stated what this was — a portfolio website.

去年,我特別指出了從頭開始重新設計網站的重要性。 我想要一個簡單而簡約的外觀,清楚地說明這是什么-一個投資組合網站。

After I rebuilt my website from the ground up it seemed like everywhere I turned there was another article about adding a dark mode to your website.

從頭開始重新構建網站后,似乎到處都是轉彎,還有另一篇關于向您的網站添加暗模式的文章。

At first I didn’t think it would make that big of a difference because, while I am partial to darker colors, I felt like my website was a good balance between bright, fun colors and darker fonts.

起初我不認為這會帶來太大的改變,因為雖然我偏愛深色,但我覺得我的網站在明亮,有趣的色彩和深色字體之間取得了很好的平衡。

I read some of the articles I mentioned earlier and the more I thought about it the more I decided to go for it.

我讀了我之前提到的一些文章,對它的思考越深,我決定就越去追求它。

I took some inspiration from Flavio Copes who wrote a terrific article on this very subject. Unlike what Flavio decided to do with his site, I didn’t add the user’s choice to local storage.

我從弗拉維奧·科普斯(Flavio Copes)那里獲得了一些啟發,他在這個主題上寫了一篇很棒的文章 。 與Flavio決定使用其網站不同,我沒有將用戶的選擇添加到本地存儲中。

This is due, in part, to the differences between our sites. I have a static site and there are no redirects/separate pages aside from the blog which is on a different platform so users generally won’t be refreshing the page. It is a neat option and one that I may add in later on.

這部分是由于我們站點之間的差異。 我有一個靜態網站,除了博客(位于另一個平臺上)之外,沒有重定向/單獨的頁面,因此用戶通常不會刷新頁面。 這是一個很好的選擇,稍后我可以添加。

Ok, let’s dig into the nuts and bolts of how I accomplished my dark mode toggle.

好的,讓我們深入研究如何完成黑暗模式切換。

代碼 (The Code)

The code to achieve this was fairly simple. I took the same approach as Flavio did and added the style changes through CSS. I had to take a few more steps because I have an image on my landing page.

實現此目的的代碼非常簡單。 我采用了與Flavio相同的方法,并通過CSS添加了樣式更改。 我必須再執行幾步,因為我的目標網頁上有一張圖片。

I had to use the !important flag on some of the rules because they were not being applied properly. This was the easiest approach to implement and I know it’s not advised to use this flag so I’ll be looking for an alternative in the near future.

我必須在某些規則上使用!important標志,因為它們未正確應用。 這是最簡單的實現方法,我知道不建議使用此標志,因此我會在不久的將來尋找替代方法。

Here is the JavaScript I used to get my toggle switch working correctly:

這是我用來使切換開關正常工作JavaScript:

I start by selecting my div with an id of light-dark-mode-container and adding an event listener to it.

我首先選擇ID為light-dark-mode-container div ,然后向其添加事件監聽器 。

Next, I set my variables of everything, which selects all content on the page, and projectTiles because this class belongs to a particular set of overlays I do not want to have a background of a solid color.

接下來,設置我的everything變量,該變量將選擇頁面上的所有內容,并選擇projectTiles因為此類屬于特定的一組疊加層,所以我不想使用純色背景。

Next, since I’m using querySelectorAll which returns a static NodeList, I loop over all of the elements within both NodeLists and either toggle the class dark or completely remove it from the elements returned by the variable projectTiles.

接下來,由于我使用的是返回靜態NodeList的 querySelectorAll ,因此我遍歷了兩個NodeList中的所有元素,然后將類切換為dark或將其從變量projectTiles返回的元素中完全刪除。

What I’m left with is a container at the top of my website with a toggle switch that allows the user to toggle between light and dark mode.

我剩下的是網站頂部的容器,其中有一個切換開關,允許用戶在亮和暗模式之間切換。

I hope you enjoyed this post and maybe you learned something too! If you decide to implement this on your own website or your next project please share it with me (leave me a comment or shout at me on Twitter). I’m always happy to see the work and projects that others create.

我希望您喜歡這篇文章,也許您也學到了一些東西! 如果您決定在自己的網站或下一個項目中實施此操作,請與我分享(在Twitter上給我留言或大喊大叫)。 我總是很高興看到其他人創建的工作和項目。

This post was posted on my blog where I write articles related to front end web development. I also cross post over at Dev.to, so if you’re on that platform you can find my work as well!

這篇文章發布在我的博客上,我在那里寫有關前端Web開發的文章。 我也在Dev.to上發布了文章 ,因此,如果您在該平臺上,也可以找到我的作品!

While you’re there why not sign up for my Newsletter? I promise I’ll never spam your inbox and your information will not be shared with anyone else.

當您在那里時,為什么不注冊我的時事通訊 ? 我保證我永遠不會向您的收件箱發送垃圾郵件,并且不會與其他任何人共享您的信息。

Have an awesome day filled with love, joy, and coding!

美好的一天充滿愛,歡樂和編碼!

翻譯自: https://www.freecodecamp.org/news/how-i-added-dark-mode-to-my-website-484bc3cb0318/

hexo博客添加暗色模式

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391623.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391623.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391623.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leetcode 331. 驗證二叉樹的前序序列化

序列化二叉樹的一種方法是使用前序遍歷。當我們遇到一個非空節點時,我們可以記錄下這個節點的值。如果它是一個空節點,我們可以使用一個標記值記錄,例如 #。_9_/ \3 2/ \ / \4 1 # 6 / \ / \ / \ # # # # # # 例如&#xff0…

mongodb數據可視化_使用MongoDB實時可視化開放數據

mongodb數據可視化Using Python to connect to Taiwan Government PM2.5 open data API, and schedule to update data in real time to MongoDB — Part 2使用Python連接到臺灣政府PM2.5開放數據API,并計劃將數據實時更新到MongoDB —第2部分 目標 (Goal) This ti…

4.kafka的安裝部署

為了安裝過程對一些參數的理解,我先在這里提一下kafka一些重點概念,topic,broker,producer,consumer,message,partition,依賴于zookeeper, kafka是一種消息隊列,他的服務端是由若干個broker組成的,broker會向zookeeper,producer生成者對應一個…

javascript初學者_針對JavaScript初學者的調試技巧和竅門

javascript初學者by Priyanka Garg由Priyanka Garg My intended audience for this tutorial is beginner programmers. You’ll learn about frustration-free debugging with chrome dev tools.本教程的目標讀者是初學者。 您將學習使用chrome開發工具進行無挫折的調試。 D…

leetcode 705. 設計哈希集合

不使用任何內建的哈希表庫設計一個哈希集合(HashSet)。 實現 MyHashSet 類: void add(key) 向哈希集合中插入值 key 。 bool contains(key) 返回哈希集合中是否存在這個值 key 。 void remove(key) 將給定值 key 從哈希集合中刪除。如果哈希…

ecshop 前臺個人中心修改側邊欄 和 側邊欄顯示不全 或 導航現實不全

怎么給個人中心側邊欄加項或者減項 在模板文件default/user_menu.lbi 文件里添加或者修改,一般看到頁面都會知道怎么加,怎么刪,這里就不啰嗦了 添加一個欄目以后,這個地址跳的頁面怎么寫 這是最基本的一個包括左側個人信息,頭部導航欄 <!DOCTYPE html PUBLIC "-//W3C//…

leetcode 706. 設計哈希映射

不使用任何內建的哈希表庫設計一個哈希映射&#xff08;HashMap&#xff09;。 實現 MyHashMap 類&#xff1a; MyHashMap() 用空映射初始化對象 void put(int key, int value) 向 HashMap 插入一個鍵值對 (key, value) 。如果 key 已經存在于映射中&#xff0c;則更新其對應…

數據庫語言 數據查詢_使用這種簡單的查詢語言開始查詢數據

數據庫語言 數據查詢Working with data is becoming an increasingly important skill in the modern workplace. 在現代工作場所中&#xff0c;處理數據已成為越來越重要的技能。 Data is no longer the domain of analysts and software engineers. With todays technology,…

面向對象編程思想-觀察者模式

一、引言 相信猿友都大大小小經歷過一些面試&#xff0c;其中有道經典題目&#xff0c;場景是貓咪叫了一聲&#xff0c;老鼠跑了&#xff0c;主人被驚醒&#xff08;設計有擴展性的可加分&#xff09;。對于初學者來說&#xff0c;可能一臉懵逼&#xff0c;這啥跟啥啊是&#x…

typescript 使用_如何使用TypeScript輕松修改Minecraft

typescript 使用by Josh Wulf通過喬什沃爾夫(Josh Wulf) 如何使用TypeScript輕松修改Minecraft (How to modify Minecraft the easy way with TypeScript) Usually, modifying Minecraft requires coding in Java, and a lot of scaffolding. Now you can write and share Min…

Python:在Pandas數據框中查找缺失值

How to find Missing values in a data frame using Python/Pandas如何使用Python / Pandas查找數據框中的缺失值 介紹&#xff1a; (Introduction:) When you start working on any data science project the data you are provided is never clean. One of the most common …

監督學習-回歸分析

一、數學建模概述 監督學習&#xff1a;通過已有的訓練樣本進行訓練得到一個最優模型&#xff0c;再利用這個模型將所有的輸入映射為相應的輸出。監督學習根據輸出數據又分為回歸問題&#xff08;regression&#xff09;和分類問題&#xff08;classfication&#xff09;&#…

leetcode 54. 螺旋矩陣(遞歸)

給你一個 m 行 n 列的矩陣 matrix &#xff0c;請按照 順時針螺旋順序 &#xff0c;返回矩陣中的所有元素。 示例 1&#xff1a; 輸入&#xff1a;matrix [[1,2,3],[4,5,6],[7,8,9]] 輸出&#xff1a;[1,2,3,6,9,8,7,4,5] 示例 2&#xff1a; 輸入&#xff1a;matrix [[1,…

微服務架構技能

2019獨角獸企業重金招聘Python工程師標準>>> 微服務架構技能 博客分類&#xff1a; 架構 &#xff08;StuQ 微服務技能圖譜&#xff09; 2課程簡介 本課程分為基礎篇和高級篇兩部分&#xff0c;旨在通過完整的案例&#xff0c;呈現微服務的開發、測試、構建、部署、…

phpstorm 調試_PhpStorm中的多用戶調試

phpstorm 調試by Ray Naldo雷納爾多(Ray Naldo) PhpStorm中的多用戶調試 (Multi-User Debugging in PhpStorm) 使用Xdebug和DBGp代理 (Using Xdebug and DBGp Proxy) “Er, wait a minute… Don’t you just use xdebug.remote_connect_back which has been introduced since …

Tableau Desktop認證:為什么要關心以及如何通過

Woah, Tableau!哇&#xff0c;Tableau&#xff01; By now, almost everyone’s heard of the data visualization software that brought visual analytics to the public. Its intuitive drag and drop interface makes connecting to data, creating graphs, and sharing d…

約束布局constraint-layout導入失敗的解決方案 - 轉

今天有同事用到了約束布局&#xff0c;但是導入我的工程出現錯誤 **提示錯誤&#xff1a; Could not find com.Android.support.constraint:constraint-layout:1.0.0-alpha3** 我網上查了一下資料&#xff0c;都說是因為我的androidStudio版本是最新的穩定版導入這個包就會報這…

算法復習:冒泡排序

思想&#xff1a;對于一個列表,每個數都是一個"氣泡 "&#xff0c;數字越大表示"越重 "&#xff0c;最重的氣泡移動到列表最后一位&#xff0c;冒泡排序后的結果就是“氣泡”按照它們的重量依次移動到列表中它們相應的位置。 算法&#xff1a;搜索整個列表…

leetcode 59. 螺旋矩陣 II(遞歸)

給你一個正整數 n &#xff0c;生成一個包含 1 到 n2 所有元素&#xff0c;且元素按順時針順序螺旋排列的 n x n 正方形矩陣 matrix 。 示例 1&#xff1a; 輸入&#xff1a;n 3 輸出&#xff1a;[[1,2,3],[8,9,4],[7,6,5]] 解題思路 按層進行數字的填充&#xff0c;每一層…

前端基礎進階(七):函數與函數式編程

縱觀JavaScript中所有必須需要掌握的重點知識中&#xff0c;函數是我們在初學的時候最容易忽視的一個知識點。在學習的過程中&#xff0c;可能會有很多人、很多文章告訴你面向對象很重要&#xff0c;原型很重要&#xff0c;可是卻很少有人告訴你&#xff0c;面向對象中所有的重…