GithubHelp home page GithubHelp logo

ashkheid-zz / prc---css-var-js-webpack Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 59 KB

Reading and manipulating css custom variables with JS

HTML 31.09% JavaScript 44.50% CSS 24.41%
css javascript html cssom array-methods

prc---css-var-js-webpack's Introduction

Reading and manipulating css custom variables with JS

This is a practice project, The goal is:

reading some custom css-variables from a *.css file, adding it into a .html file , and make it interactively changeable

_for more information on `` read these two articles: MDN | CSS-Tricks

File 01

graph LR
A((root)) --> B(01)
A --> C[index.html]
A --> D[style.css]
B --> E[step01.html]
B --> F[step01.js]

Here I'm just working with style.css containing some css-variables. the result is produced in step01.html file.

  • The step01.js doesn't do anything but logging a description about what's going on.
  • The index.html provided just for navigating between steps.

File 02

graph LR
A((root)) --> B(02)
A --> C[index.html]
A --> D[style.css]
B --> E[step02.html]
B --> F[step02.js]

Here I'm actually creating a link element in step02.js file, attaching the style.css to it and adding it into the step02.html file.

File 03

graph LR
A((root)) --> B(dist)
A --> C(src)
A --> D[package-lock.json]
A --> E[package.json]
A --> F[webpack.config.js]
B --> G[step03.html]
B --> H[step03.js]
C --> I[index.js]
A --> J[index.html]
A --> K[style.css]

With the help of webpack, I import the style.css in the index.js file and bundle it to the dist/step03.html.

File 04

graph LR
A((root)) --> B(04)
A --> C[index.html]
A --> D[style.css]
B --> E[step04.css]
B --> F[step04.html]
B --> G[step04.js]

In this example, the style.css isn't use 'cause it's completely different markUp.

There're some css-variables defined in step04.css. There's a cssData object in step04.js which is an imaginary presentation of fetched css-variables from step04.css.

Once a colored circle is clicked, the cssData is updated and the theme has changed

File 05

graph LR
A((root)) --> B(05)
A --> C[index.html]
A --> D[style.css]
B --> E[step05.css]
B --> F[step05.html]
B --> G[step05.js]

The implementation of the former file was a little complicated. There's better solution for Implementing the reColor() function, which is using setProperty on the root element.

File 06

graph LR
A((root)) --> B(06)
A --> C[index.html]
A --> D[style.css]
B --> E[step06.css]
B --> F[step06.html]
B --> G[step06.js]

Solving the problem using CSS Object Model

File 07

graph LR
A((root)) --> B(07)
A --> C[index.html]
A --> D[style.css]
B --> E[step07.css]
B --> F[step07.html]
B --> G[step07.js]
B --> H[varCollector.js]

Solving the problem using array methods and CSSOM

File 08

graph LR
A((root)) --> B(08)
A --> C[index.html]
A --> D[style.css]
B --> E[step08.css]
B --> F[step08.html]
B --> G[step08.js]
B --> H[varCollector.js]

Improving the functionality

prc---css-var-js-webpack's People

Contributors

ashkheid avatar

Watchers

 avatar

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.