npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

brandojs

v1.1.6

Published

Automatically change CSS backgrounds on any DOM element in a random or sequential order.

Downloads

42

Readme

-----------------------------------------------------

➤ Table of Contents

-----------------------------------------------------

➤ Intro

Would you like to...

  • Randomly change backgrounds on your website?
  • Smoothly rotate through a collection of CSS background images, colors, and/or gradients?
  • Change backgrounds on 1337 elements simultaneously?! (not recommended but doable 😂)
  • Impress your website visitors?

Try out bRando.js!

The bRando.js library lets you specify what HTML element(s) to add a background changer to, what CSS backgrounds to use, and more. It is usable in the browser and more environments are coming soon.

-----------------------------------------------------

➤ Approach

bRando.js utilizes the pseudo-element ::after and CSS custom properties (variables) to facilitate smooth transitions. Background changer instances follow this approach:

  1. Create an ::after style definition with CSS variables and the chosen transition settings in order to update ::after backgrounds.
  2. Set subsequent backgrounds on the selected element(s) and corresponding ::after('s) in an alternating manner.
  3. Toggle the opacity of the ::after element(s) to switch between the ::after background and element background.

-----------------------------------------------------

➤ Installation

There are a couple different ways to add this library:

CDN

Skip the download, include the following code in your HTML right before </head>:

<script src="https://unpkg.com/brandojs/dist/bRando.js"></script>

Manual Download

Download the file, and include the following code in your HTML right before </head>:

<script src="./your/scripts/path/bRando.js"></script>

Of course, make sure the path points to where you put the script.

-----------------------------------------------------

➤ Verifying Installation

To test that the library is installed correctly, create a demo instance with the following code by placing it right before your page's </body> tag:

<script>
	const demo = bRando.create(); // creates a demo background changer
</script>

This will create a background changer with demo backgrounds on the <body> element. You should see something like this behind the main content:

-----------------------------------------------------

➤ Usage

Create a new background changer by calling the create() function from the bRando library and passing it an options object containing the desired settings.

const options = {
	CSSSelector: "main", // A CSS selector
	// An array of CSS backgrounds
	backgrounds: [
		"aqua", // solid color
		"linear-gradient(80deg, #0864c8 25%, #588fca 75%)", // gradient
		`url("somewhere/some-image.jpg") center/cover no-repeat`, // image
		`center / contain no-repeat url("../../media/examples/firefox-logo.svg"),
        #eee 35% url("../../media/examples/lizard.png")`, // everything
	],
	timeout: 5000, // The time between background changes in milliseconds
	random: true, // Whether to rotate through the backgrounds randomly or not
	transition: "500ms ease-in", // A CSS transition to be used when changing between backgrounds
};

const bgChanger = bRando.create(options); // create background changer with the options set above

// call next() if you want the page to load with one of the backgrounds immediately
bgChanger.next(); // remove this line if you want a smooth first transition

All options are optional and have default values if they are not included in the options object.

Learn how to control the background changer that is returned by referring to the bRando class documentation.

ℹ️ Preload Images

Be sure to preload any images used as backgrounds before creating the background changer or your end user may see partially loaded background images. There are a few ways to do this. For example, you could add preload <link> tags in the <head> of your document:

<link rel="preload" href="some-image-used-as-a-background1.jpg" as="image" />
<link rel="preload" href="some-image-used-as-a-background2.jpg" as="image" />
<link rel="preload" href="some-image-used-as-a-background3.jpg" as="image" />

⚠️ Optimize Images

Always optimize any images used as backgrounds to minimize the chance that your end user sees partially loaded background images. Use something like imagecompressor.com which allows you to adjust quality settings and a compression level for each image.

-----------------------------------------------------

➤ API Documentation

Full documentation

-----------------------------------------------------

➤ To-Do

Planned

Features and fixes planned for development.

  • Create React component

Ideas

Ideas I have thought up but will not add unless requested.

  • Add event hooks:
    • onChange()
    • afterChange()
  • Add previous()

Have a feature request? Create a new issue and select the "Feature request" type OR write the feature yourself and create a pull request.

-----------------------------------------------------

➤ Issues

Found a 🐛? Create a new issue or propose a fix by creating a pull request.

-----------------------------------------------------

➤ License

Licensed under MIT.