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

@bornfight/flipswitch

v2.0.1

Published

flipswitch.js - pure javascript solution for clipping elements inside DOM

Downloads

18

Readme

npm version GitHub last commit contributions welcome MIT license

🔨️ Why start with why

  • allows to clip fixed elements trough sections on scroll
  • it's simple to use
  • lightweight (minified ~8kb)
  • fast and customizable
  • no dependencies

📦 Getting Started

  • install flipswitch trough npm or pull ti from git
npm i @bornfight/flipswitch
  • include flipswitch to your JS and SCSS after running npm install
JS
import Flipswitch from "@bornfight/flipswitch";
SCSS
@import "~flipswitch/src/scss/flipswitch.scss";
or CSS
<link rel="stylesheet" href="flipswitch.css">

💎 Customization

HTML markup
  • data-flipswitch-class doesn't need to be different for every section (could be something like dark and light)
<p class="js-flipswitch-element">
    Flipswitch element
</p>

<section class="js-flipswitch-section" data-flipswitch-class="first-section">
    ...
</section>
<section class="js-flipswitch-section" data-flipswitch-class="second-section">
    ...
</section>
<section class="js-flipswitch-section" data-flipswitch-class="fourth-section">
    ...
</section>

<!-- default section -->
<section class="js-flipswitch-section">
    ...
</section>
Basic usage
  • element needs to have js-flipswitch-element class
  • section needs to have js-flipswitch-section class and data-flipswitch-class attribute
  • data-flipswitch-class is a flag that will define witch element will be clipped
  • library will use requestAnimationFrame() (not scroll event)
  • element will be wrapped and positioned to body
new Flipswitch();
Advanced usage
  • below example will use scroll event
  • element will be wrapped and positioned to js-parent
  • element is offset by 50px from left and -50px from top
new Flipswitch({
    parentClass: 'js-parent',
    elementClass: 'js-element',
    sectionsClass: 'js-section',
    useScroll: true,
    offsetX: 50,
    offsetY: -50
});

✅ Properties

Option | Type | Default | Example | Description ------ | ---- | ------- | ------- | ----------- parentClass | string | element parent | 'js-parent' | Element will be wrapped and moved to that parent and not to initial parent element elementClass | string | 'js-flipswitch-element' | 'js-element' | Changes default class sectionsClass | string | 'js-flipswitch-section' | 'js-section' | Changes default class useScroll | boolean | false | true | Use scroll event and not requestAnimationFrame() offsetX | number | 0 | 50 | Offsets element from top offsetY | number | 0 | -50 | Offsets element from left throttle | number | 0 | 10 | Refreshes element position every XY milliseconds (only available if useScroll: false) data-flipswitch-class | html attr | | data-flipswitch-class="red-section" | flag that will define witch element will be clipped

🚀 Useful to know

  1. every section needs to have data-flipswitch-class (look 4.) and section class (default is js-flipswitch-section)
  2. data-flipswitch-class is added to element wrapper as modifier class
  3. element needs to be position: fixed
  4. every second section doesn't need to have data-flipswitch-class - default class (and element clone) is available
  5. every element needs to have it's own Flipswitch instance (and different sections and element classes)
  6. throttle is only available if useScroll is false and value have to be in milliseconds
  7. first section on page needs to have class js-flipswitch-section but doesn't needs to have data-flipswitch-class attr