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

scrollbalance

v1.2.2

Published

Uses position: fixed to combat unsightly gaps in multi-column layouts, when columns are of different heights.

Downloads

95

Readme

ScrollBalance.js

A javascript plugin that intelligently uses position: fixed to combat unsightly gaps in multi-column layouts, when columns are of different heights. See http://gregplaysguitar.github.io/ScrollBalance.js/ for a demo.

Requires jquery version 1.7 or higher.

Installation

With npm:

npm install scrollbalance

or via cdn:

<script type="text/javascript" src="https://www.gitcdn.xyz/repo/gregplaysguitar/ScrollBalance.js/master/ScrollBalance.js"></script>

Usage

Start with side-by-side columns, for example:

<div class="column">...</div>
<div class="column">...</div>
<div class="column">...</div>

Columns could be floated, inline-block or positioned absolutely - the only requirement is that they're side-by-side on the page.

With multiple columns, the tallest will be used as the reference height which the others scroll and fix within. If there's only one column, it will scroll and fix within it's parent element.

Initialize the plugin like so:

var scrollbalance = new ScrollBalance($('.column'), {
  // options
});
scrollbalance.bind();

Or with jquery:

$('.column').scrollbalance({});
var scrollbalance = $('.column').data('scrollbalance'); // access the api

Options

  • minwidth
    disable the plugin if the screen width is less than this (default 0)
  • threshold
    threshold for activating the plugin, eg the column heights must differ by at least this amount to be affected. (default 100)

Methods

  • initialize: function ()
     Recalculate column heights and positioning, for example if content changes
  • resize: function (winWidth, winHeight)
    Handle a browser resize event
  • scroll: function (scrollTop, scrollLeft)
    Handle a browser scroll event
  • bind: function ()
    Bind resize and scroll to the window's corresponding events
  • unbind: function ()
    Remove resize and scroll from the window's corresponding events
  • disable: function ()
    Disable scrollbalance
  • enable: function ()
    Enable scrollbalance
  • teardown: function ()
    Remove all traces of scrollbalance from the content

Scroll / resize event handling

ScrollBalance.bind() binds to the window's resize and scroll events, but you may want to handle these manually to avoid binding to these events multiple times:

var scrollbalance = new ScrollBalance($('.column'));

$(window).on('resize', function () {
  var winWidth = $(window).width();
  var winHeight = $(window).height();
  scrollbalance.resize(winWidth, winHeight);

  // other resize behaviour
});

$(window).on('scroll', function () {
  var scrollTop = $(window).scrollTop();
  var scrollLeft = $(window).scrollLeft();
  scrollbalance.scroll(scrollTop, scrollLeft);

  // other scroll behaviour
});

Column wrapper div

To avoid changing the position of the columns, ScrollBalance.js creates a wrapper div inside each, and appends the column content dynamically. To avoid this, wrap the column content in a div with the class scrollbalance-inner and this will be used instead. The div should have no styling. E.g.

<div class="column"><div class="scrollbalance-inner">...</div></div>
<div class="column"><div class="scrollbalance-inner">...</div></div>

Dynamic content

If your column heights change dynamically, you'll need to call the initialize method - for example:

var scrollbalance = new ScrollBalance($('.column'));

// add some content here
...

scrollbalance.initialize();

Temporarily disabling the plugin

The plugin can be turned on and off with the enable and disable api methods. For example, for smaller screen sizes where the columns don't have room to float side-by-side:

var scrollbalance = new ScrollBalance($('.column'));

$(window).on('resize', function() {
    if ($(window).width() > 900) {
        scrollbalance.enable();
    }
    else {
        scrollbalance.disable();                    
    }
});

Removing the plugin from an element

The teardown method removes all trace of jquery-scrollbalance from an element. For example:

var scrollbalance = new ScrollBalance($('.column'));
scrollbalance.teardown();

Demo

See http://gregplaysguitar.github.io/ScrollBalance.js/ for a demo.

Sites using ScrollBalance.js

License

The plugin is licensed under the MIT License (LICENSE.txt).

Copyright (c) 2011 Greg Brown