2.0.0 • Published 4 years ago

most-visible v2.0.0

Weekly downloads
189
License
MIT
Repository
github
Last release
4 years ago

Most Visible

License Build status npm version Size Size

A JavaScript module and jQuery plugin which returns the most visible element from a given set.

Installation

Download

CDN

<script src="https://unpkg.com/most-visible@2.0.0/dist/most-visible.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/most-visible@2.0.0/dist/most-visible.js"></script>

Package Managers

Install via yarn:

$ yarn add most-visible

Install via NPM:

$ npm install most-visible --save

Usage

Browser

jQuery

The plugin will automatically be added to any global (window) version of jQuery:

$('.my-elements').mostVisible().addClass('most-visible');

// with options
$('.my-elements').mostVisible({percentage: true, offset: 160}).addClass('most-visible');

Vanilla JavaScript

You can pass in either a selector string:

const element = mostVisible('.my-elements');

Or a NodeList:

const element = mostVisible(document.querySelectorAll('.my-elements'));

Webpack etc.

import mostVisible from 'most-visible';

const element = mostVisible('.my-elements');

To attach the jQuery plugin to a non-global version of jQuery you must call .makejQueryPlugin:

import $ from 'jquery';
import {mostVisible, makejQueryPlugin} from 'most-visible';

makejQueryPlugin($, mostVisible);

$('.my-elements').removeClass('active').mostVisible().addClass('active');

Options

OptionTypeDescriptionDefault
percentagebooleanWhether to calculate the visibility of an element as a percentage of its heightfalse''
offsetnumberA pixel offset to use when calculating visibility. Useful for e.g fixed headers.0

Modify the mostVisible.defaults object to change default option values:

mostVisible.defaults.percentage = true;
mostVisible.defaults.offset = 160;

License

Released under the MIT license

2.0.0-beta.2

4 years ago

2.0.0

4 years ago

1.5.0

6 years ago

1.4.0

7 years ago

1.4.0-beta.0

7 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.9.2

10 years ago

0.9.1

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.3

10 years ago

0.0.1

10 years ago