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

@fiddle-digital/string-scroll

v1.0.4

Published

StringScroll is a JavaScript library designed for sophisticated scrolling and animation control on web pages. It provides advanced capabilities for managing parallax effects, scroll-based animations, and more, offering a comprehensive solution for creatin

Downloads

386

Readme

Alpha Alpha

Overview

StringScroll is a JavaScript library designed for sophisticated scrolling and animation control on web pages. It provides advanced capabilities for managing parallax effects, scroll-based animations, and more, offering a comprehensive solution for creating interactive and visually appealing web experiences.

Installation

using a package manager:


npm  i  @fiddle-digital/string-scroll

import  {  StringScroll  }  from  '@fiddle-digital/string-scroll'

Usage

The use of scroll is only possible with an existing window object.


const  scroll =  StringScroll.getInstance()

Params

Additional HTML attributes help control some aspects of element behavior.

| HTML attribute | Description | |--|--| | data-string-progress | This attribute is used in conjunction with other scrolling customization options. It is suitable for more complex scrolling effects. Adds the css variable --string-progress. | | data-string-parallax | The attribute takes a parallax value and applies a parallax effect without any extra actions. | | data-string-offset | It accepts values in the format of "100px 100px" or "20% 30%" which will denote the offset from the top and bottom of the screen | | data-string-start | It accepts values in the format of "top top", "top bottom","bottom top","bottom bottom". | | data-string-end | It accepts values in the format of "top top", "top bottom","bottom top","bottom bottom". | | data-string-id | The value of the element identifier by which you can track updates in JavaScript and data-string-connect | | data-string-repeat | When the element appears on the screen, the class -inview is added to it, and the data-repeat value removes it when the element goes beyond the screen bounds. | | data-string-lerp | An attribute that adds the ability to track lerp values in an element. Adds the css variable --scroll-lerp | | data-string-connect | The attribute accepts the scroll string from another element and duplicates its progress value. |

data-string-progress

This example demonstrates how to animate an element that responds to scroll progress. The element scrolls horizontally depending on the page scrolling progress.

HTML

<div class="example" data-string data-string-progress></div>

CSS

.example{
	transform: translate(calc(100% * var(--string-progress));
}

When the user scrolls the page, the element with class example is smoothly shifted in the horizontal direction. The speed and amount of displacement depends on the speed and level of page scrolling. This effect is particularly useful for creating dynamic visual effects that respond to user actions.

data-string-parallax

This example demonstrates how to apply a parallax effect to an element using the data-string-parallax attribute. The element will move at different speeds relative to the scrolling speed of the page, creating the illusion of depth.

HTML

<div class="example" data-string data-string-parallax="0.3"></div>

In this example, an element with class example will move with a parallax effect when scrolling the page. The data-string-parallax attribute with a value of 0.3 determines the intensity of the parallax effect. A value of 0.3 means that the element will move at a speed equal to 30% of the page scroll speed.

Events

The "on" method is used to register event handlers for certain types of scrolling or interaction events. This can include scroll, scroll-progress, element intersection, and scroll-progress events. The method allows you to define callback functions that are executed when the corresponding event occurs.

on(eventType: string, callback: Function, id?: string): void
  • eventType (string): The type of event to respond to. Possible values include "scroll", "progress", "intersection", "scroll-progress".
  • callback (Function): The function that will be called when the specified event occurs. The arguments passed to this function depend on the event type.
  • id (string, опціонально): An identifier that can be used to identify a specific item or group of items for which the event should be tracked.

Track scroll events:

scroll.on("scroll",  function(scrollPos) {
	console.log("Current scroll position:", scrollPos);
});

In this example, with each scroll offset, the current scroll position is output.

Track the scrolling progress of an item:

scroll.on("progress", function(progress) {
  console.log("Scroll progress of element:", progress);
}, "elementId");

Here, the callback function is executed with the scroll progress value for the element with the specified ID.

Functions

| Function | Description | |--|--| | setMobileMode(mode) | Sets the scroll mode for mobile devices. | | setDesktopMode(mode) | Sets the scroll mode for desktop devices. | | disableScroll() | Disables scrolling functionality. | | enableScroll() | Enables scrolling functionality. | | setSpeedAccelerate(speed) | Sets the acceleration rate for scrolling animations. | | setSpeedDecelerate(speed) | Sets the deceleration rate for scrolling animations. | | setScrollFactor(factor) | Sets the scroll factor. | | setSafariFactor(safariFactor) | Sets the scroll factor specific to the Safari browser. | | setScrollMode(mode) | Sets the general scroll mode. | | enableById(id) | Activates the element by the specified ID. | | disableById(id) | Deactivates the element by the given ID. | | setProgressStatus(status) | Sets the activity status of the scroll progress. | | setParallaxStatus(status) | Sets the activity status of the parallax effect. | | forceUpdateParallax() | Force refreshes parallax effects. | | overflowHidden() | Activates the "overflow hidden" mode. | | overflowAuto() | Disables the "overflow hidden" mode and sets the "overflow auto" behavior. |