viewport-focus
Given a list of DOM elements, return the one closest to the focal point of the browser viewport
Table of Contents
Install
npm install viewport-focus --saveyarn add viewport-focus
Install a document.scrollingElement polyfill for older browser support
Usage
<script src="//unpkg.com/underscore@1.8.3/underscore.js"></script><script src="//unpkg.com/viewport-focus/dist/viewport-focus.js"></script><script> var getViewportFocus = windowviewportFocus; var elements = document; // jQuery: var elements = $('section')[0]; { var closestEl = ; // closestEl is at your command } ; window;</script>});
In the Future
;; document;
API
closestToMiddle(elements: Array|NodeList, offset?: String) => HTMLElement
offset
bounds
- top and bottom are compared to the viewport middle — defaultmiddle
- element height is compared to viewport middle
Contribute
Pull requests accepted!
License
ISC LICENSE
Copyright © 2017 Push the Red Button