Skip to content

justMoritz/scrollimate.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scrollimate!

Scrollimate focuses on features and functions related to scrolling, animations (hence the name), but includes also other functionalities.

Table of Contents

Setup and Usage:

This is a jQuery Plugin, so you'll need jQuery. Include jQuery. Include scrollimate.js.

<script src="path/to/your/scripts/jquery-2.1.4.min.js"></script>
<script src="path/to/your/scripts/scrollimate.js"></script>

Each of the functionalities are implemented as methods of the scrollimate object. That means you just need to call the method you want, or you can use the handy init function and just need one call for them all!

1.) INIT METHOD

(Parallax is called via the init method)

JSON Method

The init function takes a single argument, a JavaScript Object. Inidicate the name of the function as the key, and the arguments for that function as the value, like so:

scrollimate.init({
    'saScroll', true
});

will initiate the Smooth Anchor Sroll and Parallax functions

Classic Init Method

The init function takes a single argument, an array of the methods you want to use, for example:

scrollimate.init(['saScroll', 'parallax'])

will initiate the Smooth Anchor Sroll and Parallax functions

2.) CALLING METHODS MANUALLY

While you can call (almost) every method via init, you can also call the methods each manually, such as:

scrollimate.saTabs();

which will initiate the saTabs Function

3.) jQuery Method

Many Methods can be called as an extension of jQuery. See full documentation below for more detailed instructions.

$('.your-selector').saRipple({
    color: "rgba(0,255,0,0.7)",
    interaction: "mouseover",
    noclass: true
});

The Methods

What does Scrollimate Entail? Let's take a look:



SA Parallax

SA PARALLAX SAMPLE

The original scrollimate function. You have to call SA Parallax with the init function.

BASIC SETUP:

  1. Follow the Instructions for Scrollimate Installation
  2. add the following data-attribute to the element you wish to parallax scroll: data-sabglayer
  3. Call the init Function with: <script> scrollimate.init(['saParallax']); </script>

ADVANCED SETUP:

You can tell the data-sabglayer attribute how your parallax animation should behave. By Default, it will simply start at the top and will scroll at half the speed that the page once you start scrolling. The data-sabglayer will take two arguments:

Adjust scroll speed

  • Supply a single number like so: data-sabglayer="0.5"

Supply it a single number, this is the speed at which you want the element to scroll relative to the page speed. To create several layers of parallax, or simply to more fine-tune the effect, you can se the data-sabglayer attribute to any floating point value between 0 (which will cause the element to scroll normally) and 2 (which will cause the element to appear static on the page).

You can also use any number larger than 2, which will cause the element to scroll in the opposite direction of the scroll. And yes, you can also use negative numbers and make the element scroll faster than the page!

Centering / Offset Control

SA PARALLAX SAMPLE

See how in this example, the top hero-image parallaxes right away, but each following elements (images) only when it comes into view, and consistently for each element? SA Parallax can do that!

You can supply more than one argument to SA Parallax. This is useful if the element you wish to parallax is not at the top. Supplying two elements will cause the eement to only start parallaxing once in view.

NEW in 1.3:

Keep Elements Centered

  • Supply two arguments (separated by comma), with the second argument set to center like so: data-sabglayer="-0.5, center"

This will calculate the parallax so that the element will be in it's “ideal” position when centered vertically on the screen. Plus, (ideally) you would never see it parallax out of view in either direction. (Mileage may vary...)

Custom Offset Elements

  • Supply a second argument separated by comma like so: data-sabglayer="-0.5, 0.25"

With this, you can define the position of parallaxing element. This is useful if you want the fine-control the element’s be position. This number is the fraction it is offset by it’s own hight. For example, 0.5 on a 500px tall element will cause it to be offset by 250px, 1 by 500px, etc.

If you don't want the element to be offset, but not start parallaxing until in view, simply set the second number to 0, like so: data-sabglayer="1.5, 0"

MOBILE CONTROL

By default, parallax will not be enabled on screen sizes smaller than 768px. (Sidenote: This applies to initial screen-size: Whatever your page loaded with, determined whether or not parallax is enabled. This is by design so that check is not performed over and over).

You can re-enable mobile parallax by calling the enableMobile before the saParallax method like so: <script> scrollimate.init(['enableMobile', 'saParallax']); </script> (If you are running the init function with other methods the order doens't matter, as long as saParallax gets called last).



SA (Smooth Anchor) Scroll

SMOOTH ANCHOR SCROLL SAMPLE

Smoothly scrolls to elements on websites that contain anchor scrolls. Instead of jumping to a point in the page, website scrolls smoothly (and at a consistent speed) to each anchor.

BASIC SETUP:

  1. Follow the Instructions for Scrollimate Installation
  2. Call the Method once on the page: <script> scrollimate.saScroll; </script> (You may also use the init function by supplying 'saScroll' as an additional argument)

ADVANCED SETUP:

The above method cancels any scroll on user-input, in order to preserve and respect the user's scroll before the automatic scroll. Alternatively, you can force the scroll by calling the method with a force argument like so:

scrollimate.saScroll('force')

There is also a provision for a callback, just remember to decide on the force parameter first. Usage:

scrollimate.saScroll( false, you-callback() )

_



SA Tabs

TABSCROLL SAMPLE

Create simple, bookmarable, browser-history-respecting tab content on any website. No cluttered Markup: You just need to add one custom data-attribute.

MARKUP:

You need to have two things:

1.) A Navigation of links, with each link wrapped in a parent.

In the collection of links, link the links via #s to the sections. For example, you may have two divs, one has the id of id="one", the other id="two" Your links should link to href="#one" and href="#two".

Wrap each link in a parent. (This is important for styling, or if you are using a list)

Wrap each parent to a link in another parent, and give it the following attribute "data-tabscrollnavcontainer".

It should look something like this:

<ul data-tabscrollnavcontainer>
    <li>
        <a href="#one">One</a>
    </li>
    <li>
        <a href="#two">Two</a>
    </li>
</ul>
---- or something like ----
<div data-tabscrollnavcontainer>
    <div>
        <div>
            <a href="#one">One</a>
        </div>
        <div>
            <a href="#two">Two</a>
        </div>
    </div>
</div>

2.) A collection of "tabs", the content you want to display as tabs.

I recommend it to look something like this:

<div>
    <div id="one">
        ...
    </div>
    <div id="tow">
        ...
    </div>
</div>
---- or something like ----
<article>
    <section id="one">
        ...
    </section>
    <section id="two">
        ...
    </section>
</article>

Note: (The class for the active tab on the navigation is .tabscroll_activeNavi)

SETUP:

  1. Follow the Instructions for Scrollimate Installation
  2. Call the Method once on the page: <script> scrollimate.saTabs; </script> (You may also use the init function by supplying 'saTabs' as an additional argument)

ADVANCED SETUP:

Transitions

You can control the type of transition between tabs with the data-tabscrollnavcontainer attribute. You can set it to:

  • fade
  • slide
  • or leave blank for no transition at all

Non-Index Version

You may not want your tabs to be indexed / indexable. SA Tabs keeps track of your tabs via the URL, by adding a fragment (“hash”) to the end of the URL. But what if you have an application on your page that already does that?

Now SA Tabs can accomodate, by simply calling the nonIDTabs(); method some time after the initial setup. (You can it as an additional argument to the init method, after the saTabs Method) This will not index your tabs, not write to the URL, but still keep the same markup and functionality for your tabs.

EXCLUDE LINKS

You want to have a link within your navigation that does something else. An external link, a popup link, etc. This is possible by simply adding the data-saexclude attribute to the anchor element.

Non-Indexed Version

You may not want your tabs to be indexed / indexable. Tabscroll keeps track of your tabs via the URL, by adding a fragment (“hash”) to the end of the URL. But what if you have an application on your page that already does that?

Now Tabscroll can accomodate, by simply calling the saTabs.nonIDTabs(); method some time after you included tabscroll.js. This will not index your tabs, not write to the URL, but still keep the same markup and functionality for your tabs.

Event

SA Tabs triggers a custom event, satabchanged when a tab change is invoked. You can listen to this event like so $(document).on('satabchanged', your-custom-function());

WCAG compliance

SA Tabs auto-generated markup is using best practices according to https://www.w3.org/TR/wai-aria-practices/examples/tabs/tabs-1/tabs.html



SA Scroll Class

Will add a specifiable class to any element when a target element is scrolled, and remove it when it stops scrolling.

BASIC SETUP:

  • Follow the Instructions for Installation
  • Call the Method once on the page: <script> scrollimate.scrollClass( $(window), $('.topnav'), 'scrolling' ); </script>

SA Scroll Class takes three arguments:

  1. complete jQuery Selector of the element you want to scroll (in the above example it would be the entire window, but it can be an overflow-ed div, or really anything )
  2. complete jQuery selector of the element that you want to add the class to (in the above example we are adding a class to the element with the .topnav class)
  3. The name of the class you want to add

In the above example, the .topnav Element will get the scrolling class when the window is scrolled.



SA Accordion

(examples: https://codepen.io/justMoritz/pen/vJVZVd)

A simple horizontal accordion for an infinite number of elements.

BASIC SETUP:

  1. You will need any number elements with the same selector, for example 5 divs with the class of element. please float these elements left, inline or inline-block the, so they will be next to each other . Clearing the float etc. will be up to you.
  2. Follow the Instructions for Scrollimate Installation
  3. Call the Method once on the page with two arguments like so: <script> scrollimate.saAccordion('.element', '66.66'); </script>

Advanced SETUP:

SA Accordion takes at least one, but can take four arguments:

  1. The target elements selector (in the above example every element with the .element class)
  2. (optional) The width (in percent) of the exanded element. If none is provided, the default width is 50%.
  3. (optional) The type of event that raises the change over the element selected in argument 1. Can be click, mouseover, mouseout, etc. If left blank, defaults to CLICK
  4. (optional) You can determin the height of the element, in pixels, or in percent of the width of the individual element. (This is done via padding-bottom)

jQuery Method:

You can run it via jQuery as well: $('.secondElement').saAccordion();. You can pass arguments as well: $('.secondElement').saAccordion('66.66', 'mouseover', '100px');

Please note that SA Accordion works with float: left;, and will take up 100% of the width of its container, so please plan your markup accordingly.



SA Underline

(DEMO: https://codepen.io/justMoritz/pen/veMmbE)

If you like the idea of having a link underlined, because it makes them easily identifyable as a to read as a link; but you find that it makes them hard to imposisble to style, this method is for you.

This method will wrap each word inside a link (anchor tag) in it's own span, which you can then style (or style it's pseudo element). See the Demo link for some examples.

for full functianlity (aka, with arguments), this method can current not be called with the init method :(

BASIC SETUP:

The following will target all links:

  1. Follow the Instructions for Scrollimate Installation
  2. Call the Method once on the page with two arguments like so: <script> scrollimate.saUnderline(); </script>
  3. Apply the styles you want to a span:before (or something simliar).

note: You can call this basic setup via this init() method.

Advanced SETUP:

If you pass a parameter, it will target

1 Same as above, but ... 2. ...call with scrollimate.saUnderline( $('your-selector-here') );

jQuery Method:

$('.another_dimension').saUnderline();. It's really that simple!



SA Ripple

(DEMO: https://codepen.io/justMoritz/pen/qVxPBZ)

Add a material-design-like ripple effect that activates on click.

for full functianlity (aka, with arguments), this method can current not be called with the init method :(

BASIC SETUP:

The following will target all links:

  1. Follow the Instructions for Scrollimate Installation
  2. Give the elements you want to have the ripple-effect a class of .ripple.
  3. Call the Method once on the page with like so: <script> scrollimate.saRipple(); </script>

note: You can call this basic setup via this init() method.

jQuery Method:

You can also call it via jQuery like $('.your-selector').saRipple();

Advanced SETUP:

You can set the ripple color in 3 ways:

  • use default: White. Nothin is needed other than the call the function one time on the page
  • When initializing saRipple, you can set the color by passing it as an argument, like so scrollimate.saRipple({color: #ff4400});
  • add the data-ripplecolor attribute the dom element, and put the complete CSS color therein

You can also target just a specifc element by passing a target of the complete jQuery selector like so: scrollimate.saRipple({target: $(your-selector-here) });

You can also cause the ripple effect on mouseover, etc. by passing an interaction argument like so: scrollimate.saRipple({interaction: 'mouseover' });

You can also set noclass to true, in which case the target element will not inherit the basic styles required to make ripple effect work. (display: inline-block, overflow: hidden, position relative). Remember to apply them manually!

Finally, you can combile all the arments and may end up with something like this:

scrollimate.saRipple({
  color: 'rgba(0,255,0,0.05)',
  interaction: 'mouseover',
  target: $('.mouseclass'),
  noclass: true
});

jQuery Advanced Method:

$('.your-selector').saRipple({
    color: "rgba(0,255,0,0.7)",
    interaction: "mouseover",
    noclass: true
});

note: You can currently not call this advanced setup via this init() method.



springyElement

(DEMO: https://codepen.io/justMoritz/pen/KYbypw)

Adds a “springy Element” method which allows items to be slightly dragged by the curser or touch events and spring back when released, out-bounded or travelled a certain amount of pixels.

BASIC SETUP:

jQuery Method:

Call on any jQuery-able element like so: $('your-selector-here').springyElement();

note: Calling this method via the init() method is currently untested !

Advanced SETUP:

Takes one argument, the amount of pixels an element can travel (20px by default) $('your-selector-here').springyElement(200);

note: You can currently not call this advanced setup via this init() method.



scrollstuff

Simple jQuery “stuff is scrolled into view so let's add a class” plugin

Usage:

Basic

scrollstuff Extends the jQuery Object with a new method, so the easiest usage is like this:

$('your-selector-here').scrollstuff({});

Advanced

You van also run scrollstuff with arguments

$('your-selector-here').scrollstuff({
  classname: 'custom-class-name',
  delay: 700,
  repeat: true
});

The scrollstuff object current accepts the following arguments in object notation:

  • classname (string) — name of the class to attach to object. 'this--nowinview' by default.
  • delay int — delay until class is added, in milliseconds
  • repeat boolean whether or not the animation repeats when it's out and in of view again

That's it! Have fun and enjoy the ride and all that good stuff!

About

Utilities jQuery Library, vaguely related to Animation (scrolling related and not) :)

Resources

Stars

Watchers

Forks

Packages

No packages published