1.0.12 • Published 1 year ago

custom-scroll-behaviors v1.0.12

Weekly downloads
-
License
MPL 2.0
Repository
-
Last release
1 year ago

custom-scroll-behaviors-js (v1.0.7) - in development

Library for scroll events on webpages, including parallax effects and much more, easy to use with custom elements and JS only approach (coming soon). See test/example projects and the source at github. Supports all known desktop and mobile browsers (except IE and Opera mini).

current version (1.0) supports

  • custom html elements for scroll behaviors
  • predefined behaviors for
    • vertical/horizontal movement
    • color change
    • opacity change
  • custom behavior to adjust to your needs
  • automatically adjust the height of the body (optional)

next version (1.1) will support:

  • js only approach (without custom html)
  • animation types (like ease)

Install and Import

You can install the module

  • with npm: npm i custom-scroll-behaviors
  • without npm: download the package and move it into your project

To import

  • in simple projects (front-end html import):

    <head>
      <script type="module" src="../../target/index.js"></script>
      <script type="module">
        import {
          scrollElementsConfig,
          scrollHandler,
        } from "../../target/index.js";
        scrollElementsConfig.autoSizePage = true;
        scrollHandler.init();
      </script>
    </head>
  • in React projects:

    React.useEffect(() => {
      const loadingScrollBehavior = import("custom-scroll-behaviors");
      loadingScrollBehavior.then((scrollBehavior) => {
        scrollBehavior.scrollElementsConfig.autoSizePage = true;
        scrollBehavior.scrollHandler.init();
      });
    }, []);

Usage of custom HTML elements

add the behaviors to an element by adding the custom element as a child

<div class="some-style">
  <vertical-scroll-behavior
    start="0px"
    end="700px"
    start-pos="0vh"
    end-pos="90vh"
  ></vertical-scroll-behavior>
  <rgba-color-scroll-behavior
    start="100px"
    end="1000px"
    start-color="#ff0000ff"
    end-color="#0000ffff"
  >
  </rgba-color-scroll-behavior>
</div>

Elements

Name
vertical-scroll-behavior
horizontal-scroll-behavior
visibility-scroll-behavior
rgba-color-scroll-behavior
custom-scroll-behavior

Properties of the custom elements

On all behaviors

nameusageallowed values
startstart of the animation(scroll distance from top)number with unit (px,vh,vw)(no unit will default to px)
endend of the animation(scroll distance from top)number with unit (px,vh,vw)(no unit will default to px)
speedmultiplier for scroll-valuepositive number
repeatlet the animation repeator continue itself"repeat" / "continue"optional

Each behavior also has a start and end value (like the start and end position). Of the five attributes : start,end,speed,"start-value","end-value" exactly 4 have to be specified Start and end parameters are allowed to end with +self or -self to add or remove the own height or width (mostly height)

On vertical and horizontal behaviors

nameusageallowed values
start-posposition of the element at the start of the animation(left/top of the element)number with unit (px,vh,vw)(no unit will default to px)
end-posposition of the element at the end of the animation(left/top of the element)number with unit (px,vh,vw)(no unit will default to px

On visibility behavior

nameusageallowed values
start-opacityopacity of the element at the start of the animationnumber between 0 and 1
end-opacityopacity of the element at the end of the animationnumber between 0 and 1

On rgba background color behavior

nameusageallowed values
start-colorcolor of the element at the start of the animationhex rgba value (#ffffffff)
end-colorcolor of the element at the end of the animationhex rgba value (#ffffffff)

On custom behavior

nameusageallowed values
start-valuevalue of the element at the start of the animationnumber
end-valuevalue of the element at the end of the animationnumber
css-attributename of the css attribute that is animatedstring (valid attribute)
css-attribute-unitunit of the attribute (like "px")string
css-attribute-pre-unitpre unit of the attribute (like "#" for colors)string

Usage of JS only approach

(coming soon)

Config

nameusageallowed values
autoSizePagesets the height of the body to the end of the last animation(won't be the right height for every website)boolean

General Information

interfering behaviors will be overridden by the last one

1.0.9

1 year ago

1.0.8

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago