Code Monkey home page Code Monkey logo

houdini-paint-dot-grid's Introduction

houdini-paint-dot-grid logo

Houdini paint(dot-grid)

Draw dot-grid backgrounds using CSS Paint API.

Learn mode about CSS Houdini. View other available worklets.

Usage

The easiest way to use this worklet is by adding it directly from unpkg.com:

CSS.paintWorklet.addModule('https://unpkg.com/houdini-paint-dot-grid/dist/dot-grid-worklet.js');

Check out houdini.how's guide on ways to use paint worklets from npm and using bundlers.

Then add the following CSS to the element which we want to have the dot-grid background:

.element-selector {
  background-image: paint(dot-grid);
  --dot-size: 4px;
  --dot-spacing: 8px;
  --dot-color: yellow;
}

The worklet already parses the values of the custom properties and define defaults. To support additional length units for --dot-size and --dot-spacing we can optionally load the dot-grid.js script which will register these custom properties:

<!-- ES Modules -->
<script type="module" src="https://unpkg.com/houdini-paint-dot-grid/dist/dot-grid.esm.js"></script>
<script type="module">
  import 'https://unpkg.com/houdini-paint-dot-grid/dist/dot-grid.esm.js';
</script>

<!-- UMD -->
<script src="https://unpkg.com/houdini-paint-dot-grid/dist/dot-grid.umd.js"></script>

API

paint(dot-grid)

The paint worklet is registered with the name dot-grid, and it can be used anywhere where the CSS expects an image, such as background images, border images, etc.

These custom properties can be used to customize the appearance of the dot grid:

  • --dot-size: The diameter of the dots. Default: 3px.
  • --dot-spacing: The space between each dot. Default: 6px.
  • --dot-color: The color of the dots. Default: #d2d6db.

Polyfill

To use paint worklets in browsers that don't support the Houdini Paint API yet, we may use the css-paint-polyfill library.

License

MIT License

houdini-paint-dot-grid's People

Contributors

arnellebalane avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.