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

rbackground

v0.1.1

Published

A simple background image interface in JavaScript & CSS

Downloads

1

Readme

Background.js

A simple background interface in JavaScript & CSS.

Getting Started

Via CDN

jsDeliver with GitHub:

<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/jasonzyt/[email protected]/dist/background.min.css"/>
<script src="//cdn.jsdelivr.net/gh/jasonzyt/[email protected]/dist/background.min.js"></script>

jsDeliver with npm:

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/dist/background.min.css"/>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/background.min.js"></script>

UNPKG(Better in China):

<link rel="stylesheet" href="//unpkg.com/[email protected]/dist/background.min.css"/>
<script src="//unpkg.com/[email protected]/dist/background.min.js"></script>

Via local file

Install via npm:

npm i rbackground

Usage

Samples

Random Background

new Background({
    background_list: [
        {
            "src": "./img/backgrounds/scenery_20200802.jpg",
            "copyright": "&copy;Jasonzyt / Shot in Wuhan",
            "tags": [
                "landscape",
                "horizontal"
            ]
        },
        {
            "src": "./img/backgrounds/scenery_20200816.jpg",
            "copyright": "&copy;Jasonzyt / Shot in Wuhan",
            "tags": [
                "scenery",
                "horizontal"
            ]
        }
    ]
}).random();

Only One Background

new Background().load({
    src: 'background.jpg',
    copyright: '© copyright',
    tags: ['horizontal', "tag1", "tag2"]
});

Random Background & List from URL

new Background().load_list_from_url('backgrounds.json');

Random Background & List from URL async

(async function () {
    const background = new Background();
    await background.load_list_from_url_async('backgrounds.json');
    background.random();
})();

Documentation

class Background

Constructor

new Background()

Parameters

  • obj
{
  background_element: HTMLElement|null,
  copyright_element: HTMLElement|null|false,
  require_tags: array[array[string]],
  copyright_presets: object|null,
  background_list: array[{src: string, copyright: object, tags: array[string]}],
  auto_colour: boolean,
  background_list_url: string
}

The background initialization object, containing the following fields:

  • background_element: The background element.
    Set to null to create a div element as the background element
  • copyright_element: The copyright element.
    Set to null to create a div element as the copyright element, false to disable the copyright element
  • require_tags: The tags that must be present in the background.
    For example, [["a"], ["b", "c"]] means that the background must contain ("a" tag) or ("b" tag and "c" tag).
  • copyright_presets: The copyright presets.
    The key in object is the preset name, and the value is a function that takes a copyright object and returns the copyright string.
    The default preset is "default".
    If the preset is not found or the copyright object doesn't have a preset entry, the default preset will be used.
    If no copyright preset is specified, the copyright element will simply be info.copyright.toString()
  • background_list: The background list.
    The background list is an array of objects, each containing the following fields:
    • src: The background image source.
    • copyright: The copyright info object.
    • tags: The tags that the background image contains. The tags must contain horizontal, vertical or square, because the background image will be cropped to fit the screen(element). If the background image doesn't contain the horizontal/vertical/square tag, the background image will be ignored.
  • auto_color: Whether to automatically color the copyright element. If true, the copyright element will be colored according to the main color of the background image that is below the copyright element.
  • background_list_url: The background list URL. If specified, the background list will be loaded from the URL.

Note
It will automatically add the "horizontal", "vertical" or "square" tag to require_tags by the element size.


Copyrights

Third-party Images Used

The images in demo/img/backgrounds aren't under the license.
You shouldn't give out the images without giving the source link.
The images are from HoYoVerse, Jasonzyt.
If your copyright is infringed, please contact me.
(Only one picture was not created by me. And this image is to test the auto color feature)

The project is only for learning and personal use.
Please do not use it for commercial purposes unless you have obtained the authorization of the author of the background picture.