GithubHelp home page GithubHelp logo

5t3ph / houdini-cosmic-starfield Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 4.71 MB

Generate a dynamic cosmic starfield with optional cosmic clouds and customizable gradient.

Home Page: https://codepen.io/5t3ph/pen/RwgqVZO

JavaScript 80.70% Nunjucks 9.29% CSS 10.01%
css css-houdini houdini-css-paint

houdini-cosmic-starfield's Introduction

preview of the effect showing a linear gradient from top to bottom of nearly black, dark purple, and a purpley navy, over top of which are many small dots in varying sizes and opacity, then a cloud like effect, and final the words Hello World

CSS Houdini Cosmic Starfield

From Stephanie Eckles @5t3ph - author of ModernCSS.dev.

Generate a dynamic cosmic starfield with optional cosmic clouds and customizable gradient.

Preview on CodePen

How to Use

While Houdini paint worklets have the best support out of available Houdini features, they still currently require a polyfill to ensure they are applied cross browser.

So, first include the following once in your project.

<script src="https://unpkg.com/css-paint-polyfill"></script>

Note: The polyfill will not work if the worklet is applied to pseudo elements, and may have issues with customization when applied to the body element.

Then, include the paint worklet script after the polyfill is loaded:

<script>
  CSS.paintWorklet.addModule("https://unpkg.com/houdini-cosmic-starfield");

  // Trickery to get the polyfill to draw the worklet in Firefox and Safari
  setTimeout(() => {
    document.querySelector("ANCESTOR_ELEMENT").style.width = "100.01%";
    document.querySelector("ANCESTOR_ELEMENT").style.width = "100%";
  }, 500);
</script>

Finally, use it in your styles! For best results, assign as the background-image to a dedicated element.

.cosmic-starfield-element {
  /* Number of stars */
  --cosmic-starfield-stars: 4280;
  /* 'true' or do not include to hide the clouds */
  --cosmic-starfield-clouds: true;
  /* String array of at least two hex codes */
  --cosmic-starfield-gradient-colors: #471f60, #231b6e;

  /* Use the worklet! */
  background-image: paint(cosmic-starfield);
}

!important - provided gradient colors must be in hex format.

What is CSS Houdini?

Check out other Houdini paint worklets and more info at Houdini.How.

houdini-cosmic-starfield's People

Contributors

5t3ph avatar

Watchers

 avatar  avatar

Forkers

azure-em

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.