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

grid-mosaic

v1.5.0

Published

Create a layout with random positioned items without overlapping. Set up the max amount of items to be displayed and use build-in transition to show the rest or just keep it static everything is up to you

Downloads

10

Readme

Demo

https://benjamindickens.github.io/grid-mosaic-demo/

Installation

npm install grid-mosaic

Initialization

HTML
  1. Add a container to your page with "mosaic" class.
  2. Add items with "mosaic-item" class to the container.

<div class="mosaic">

    <a href="/test" class="mosaic-item">
        <img src="https://picsum.photos/200" alt="photo">
    </a>
    
    or 
    
     <img class="mosaic-item" src="https://picsum.photos/200" alt="photo">
     
    or you can add any additional html if needed
    
     <a href="/" target="_blank" class="mosaic-item">
        <img src="https://picsum.photos/200" alt="photo">
        <div class="mosaic__tooltip">
            <div class="mosaic__tooltip-title">Title</div>
            <div class="mosaic__tooltip-content">Content</div>
        </div>
    </a>

</div>
JS
  1. Initialize the app in your js file with default set up or modify it manually.
import Mosaic from "grid-mosaic";

new Mosaic(".mosaic")

or with an option object

new Mosaic(".mosaic", options)

Options

measurement units

Choose a measurement unit you are going to use in your app.

measure: "px" / "em" / "rem" || default: "px";
dimension

Set dimensions for grid container. The value "size" specifies "min-width" and "height" of cells. It applies necessary styles to the container. By default, for desktop "grid-template: repeat(5, 90px/rem/em) / repeat(5, minmax(90px/rem/em, 1fr))". To set the correct measurement unit use option "measure". The default value of max-width for each cell is 1fr. If you don't want the mosaic to stretch for the whole page, specify the "width" value of the container in css.

dimension: {
            desktop: {
                cols: number || default : 5,
                rows: number || default : 5,
                size: number || default : 90
            },
            mobile: {
                cols: number || default : 3,
                rows: number || default : 6,
                size: number || default : 90
            },
        };
maxSize

It means max amount of cells one item can occupy.

maxSize: {
            desktop: {
                y: number || default: 3,
                x: onumber || default: 3,
            },
            mobile: {
                y: number || default: 3,
                x: number || default: 3,
            }
        };
maxItems

Max amount of items that are shown in the container. Others will appear through the animation.

maxItems: {
            desktop: number || default: null,
            mobile: number || default: null,
        };
otherElements

Takes array of objects to specify places occupied in current mosaic and places them. The example below place the el into container by assigning the rule in format "grid-area: 5 / 1 / span 2 / span 7"

otherElements: [{
        el: document.querySelector(".js-caption"),
        coordinates: {
            desktop: [5,1,2,7],
            mobile: [1,2,4,3]
          }
        }, {....}] || default: [];
bg

Draw additional background items to take over all container.

bg: true / false || default: true;
bgStyles

You may specify main color for background elements or pass the array of classes that will be implemented to elements in random sequence.

bgStyles: {
        background: #bada55 || default : #FFFFFF,
        classes: ["class-1", "class-2" ...] || default: null
        };
bgAnimation

Specify the rules for bg animation. It is activated by default. If you want to disable it set "0" or "false". Effects - allow you to pass classes that will perform the animation.

bgAnimation: {
            delay: number / false || default : 8000,
            effects: ["_slide-0", "slide-1" ...] || default : ["_illuminate-0", "_illuminate-1", "_illuminate-2", "_illuminate-3"]
        }
noSausagePatterns

Prevent items from a bad aspect ratio.

noSausagePatterns: true / false || default : true;
randomItems

Shuffle the elements in the container to get a random sequence after the page reload.

randomItems: false / true || default : true;
gaps

Specify a grid-gap. (You can do it in css.)

gaps: {
        desktop: number || default: 0,
        mobile: number || default: 0,
       };
items

Specify the items of the mosaic.

items: [...] || default: document.querySelectorAll(".mosaic-item");
autoplay

The settings of the animation (that changes the position of the elements within the container) delay. It is activated by default. If you want to disable it set "0" or "false".

autoplay: {
            delay:  number / false || default : 3500,
            preventDefaultHover: true / false || default :  false,
            opacityDefaultOutDuration: number || default: 500,
        };
on

Here you can add your custom functions.

on: {
            mouseEnter: () => { your code ...} || default: null,
            mouseLeave: func || default: null,
            beforeInit: func || default: null,
            afterInit: func || default: null
        }
maxTries

The max amount of tries of calculation an item position.

maxTries: number || default: 60 ;
breakpoint

The value of @media (in pixels).

breakpoint: number || default: 667;