A JavaScript module and jQuery plugin which returns the most visible element from a given set.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
bin
dist
examples
grunt
src
test
.editorconfig
.gitignore
.gitmodules
.jshintrc
.travis.yml
Gruntfile.js
LICENSE
README.md
package.json
yarn.lock

README.md

Most Visible v1.4.0

Build status npm version devDependency Status

Returns the most visible element from a set of elements.

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

Installation

Download

CDN

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

Package Managers

Install via yarn:

$ yarn add most-visible

Install via NPM:

$ npm install most-visible --save

Usage

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 }).addClass('most-visible');

Vanilla JavaScript

You can pass in either a selector string:

var element = mostVisible('.elements');

Or a NodeList:

var element = mostVisible(document.querySelectorAll('.elements'), {
    percentage: true
});

Or you can create a new instance:

var instance = new mostVisible('.elements');
instance.getMostVisible();

Webpack and Browserify

var mostVisible = require('most-visible');
mostVisible('.elements');

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

var $ = require('jquery');
var mostVisible = require('most-visible');

mostVisible.makeJQueryPlugin($);

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

Options

percentage (boolean) - Whether to calculate the visibility of an element as a percentage of its height. Defaults to false. offset (number) - Specify an offset to use when calculating visibility. Useful for e.g fixed headers.

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

mostVisible.defaults.percentage = true;

License

The MIT License (MIT) Copyright (c) 2019 The Most Visible authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.