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

@topmarksdevelopment/position

v1.0.3

Published

A compact tool to help position an element against another. Similar to JQuery `.position()`

Downloads

109

Readme

Position (A JavaScript package)

The result of the latest test run NPM Version

A small package to help position a floating element. This can be positioned relative to another elements' current screen position, or to a mouse event.

Links

Usage

If you want to position an element to another fixed element then you can use the sample below

return position(
    {
        anchor: document.getElementById("Anchor"),
        target: document.getElementById("Target"),
        my: "top center",
        at: "bottom center",
    }
);

If you'd rather position the element to the mouse's movement then you can use the sample below

⚠ It is recommended to debounce the below sample, just to prevent performance issues

document.addEventListener("mousemove", function(mouse){
    const target = document.getElementById("Target"),
        pos = position(
            {
                anchor: mouse,
                target: target,
                my: "top center",
                at: "bottom center",
            }
        );

    target.style.top = pos.top;
    target.style.left = pos.left;
});

Options

my: Alignment

The location on the target to position from

at: Alignment

The location on the anchor to position against

anchor: HTMLElement OR MouseEvent

The element or mouse event to anchor our target to

target: HTMLElement

The target that we're going to be positioning

collision?: CollisionHandler

How to handle collisions with the window edge
Default: bestFit

bestFitPreference?: horizontal OR vertical

This is the preferred "best" direction when collision = bestFit and there is a "best fit" horizontally and vertically
Default: horizontal

defaults?: { my: alignment, at: alignment }

The fallback values when only one property is supplied, or the property supplied is invalid
Default: { my: "top center", at: "bottom center" }

Types

The Alignment type

The Alignment will allow any of the below, plus a combination in the form vertical horizontal (e.g. top center, bottom right or center left)

  • top
  • bottom
  • center
  • left
  • right

Using a single value will default the other to center so left == center left

The CollisionHandler type

  • bestFit
    • This will find the closest fit before trying to flip the element
  • flipFit
    • This will flip the element completely vertically and horizontally
  • ignore
    • This will just ignore any collisions and place the element exactly where you wanted it