withinviewport
Advanced tools
Comparing version 2.1.0 to 2.1.2
@@ -6,4 +6,4 @@ /** | ||
* @author Craig Patik, http://patik.com/ | ||
* @version 2.0.0 | ||
* @date 2016-12-19 | ||
* @version 2.1.2 | ||
* @date 2019-08-16 | ||
*/ | ||
@@ -16,3 +16,3 @@ (function ($) { | ||
* @return {Collection} Contains all elements that were within the viewport | ||
*/ | ||
*/ | ||
$.fn.withinviewport = function (settings) { | ||
@@ -22,5 +22,11 @@ var opts; | ||
if (typeof settings === 'string') { settings = {sides: settings}; } | ||
if (typeof settings === 'string') { | ||
settings = { | ||
sides: settings | ||
}; | ||
} | ||
opts = $.extend({}, settings, {sides: 'all'}); | ||
opts = $.extend({}, settings, { | ||
sides: 'all' | ||
}); | ||
elems = []; | ||
@@ -30,3 +36,3 @@ | ||
if (withinviewport(this, opts)) { | ||
elems.push(this); | ||
elems.push(this); | ||
} | ||
@@ -57,5 +63,11 @@ }); | ||
if (typeof settings === 'string') { settings = {sides: settings}; } | ||
if (typeof settings === 'string') { | ||
settings = { | ||
sides: settings | ||
}; | ||
} | ||
opts = $.extend({}, settings, {sides: 'top'}); | ||
opts = $.extend({}, settings, { | ||
sides: 'top' | ||
}); | ||
elems = []; | ||
@@ -76,5 +88,11 @@ | ||
if (typeof settings === 'string') { settings = {sides: settings}; } | ||
if (typeof settings === 'string') { | ||
settings = { | ||
sides: settings | ||
}; | ||
} | ||
opts = $.extend({}, settings, {sides: 'right'}); | ||
opts = $.extend({}, settings, { | ||
sides: 'right' | ||
}); | ||
elems = []; | ||
@@ -84,3 +102,3 @@ | ||
if (withinviewport(this, opts)) { | ||
elems.push(this); | ||
elems.push(this); | ||
} | ||
@@ -96,5 +114,11 @@ }); | ||
if (typeof settings === 'string') { settings = {sides: settings}; } | ||
if (typeof settings === 'string') { | ||
settings = { | ||
sides: settings | ||
}; | ||
} | ||
opts = $.extend({}, settings, {sides: 'bottom'}); | ||
opts = $.extend({}, settings, { | ||
sides: 'bottom' | ||
}); | ||
elems = []; | ||
@@ -115,5 +139,11 @@ | ||
if (typeof settings === 'string') { settings = {sides: settings}; } | ||
if (typeof settings === 'string') { | ||
settings = { | ||
sides: settings | ||
}; | ||
} | ||
opts = $.extend({}, settings, {sides: 'left'}); | ||
opts = $.extend({}, settings, { | ||
sides: 'left' | ||
}); | ||
elems = []; | ||
@@ -120,0 +150,0 @@ |
{ | ||
"name": "withinviewport", | ||
"version": "2.1.0", | ||
"description": "Determine whether an element is completely within the browser viewport", | ||
"main": "withinviewport.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/patik/within-viewport.git" | ||
}, | ||
"keywords": [ | ||
"within-viewport", | ||
"browser", | ||
"detect", | ||
"event", | ||
"infinite-scroll", | ||
"scroll", | ||
"view", | ||
"viewport", | ||
"window" | ||
], | ||
"author": "Craig Patik <craig@patik.com> (http://patik.com)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/patik/within-viewport/issues" | ||
}, | ||
"homepage": "http://patik.github.io/within-viewport" | ||
"name": "withinviewport", | ||
"version": "2.1.2", | ||
"description": "Determine whether an element is completely within the browser viewport", | ||
"main": "withinviewport.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/patik/within-viewport.git" | ||
}, | ||
"keywords": [ | ||
"within-viewport", | ||
"browser", | ||
"detect", | ||
"event", | ||
"infinite-scroll", | ||
"scroll", | ||
"view", | ||
"viewport", | ||
"window" | ||
], | ||
"author": "Craig Patik <craig@patik.com> (http://patik.com)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/patik/within-viewport/issues" | ||
}, | ||
"homepage": "http://patik.github.io/within-viewport" | ||
} |
@@ -6,6 +6,6 @@ /** | ||
* @author Craig Patik, http://patik.com/ | ||
* @version 2.0.1 | ||
* @date 2017-11-18 | ||
* @version 2.1.2 | ||
* @date 2019-08-16 | ||
*/ | ||
(function(root, name, factory) { | ||
(function (root, name, factory) { | ||
// AMD | ||
@@ -23,3 +23,3 @@ if (typeof define === 'function' && define.amd) { | ||
} | ||
}(this, 'withinviewport', function() { | ||
}(this, 'withinviewport', function () { | ||
var canUseWindowDimensions = typeof window !== 'undefined' && window.innerHeight !== undefined; // IE 8 and lower fail this | ||
@@ -42,2 +42,4 @@ | ||
var containerBoundingRect; | ||
var containerScrollTop; | ||
var containerScrollLeft; | ||
var scrollBarWidths = [0, 0]; | ||
@@ -65,5 +67,6 @@ var sideNamesPattern; | ||
if (typeof options === 'string') { | ||
settings = { sides: options }; | ||
} | ||
else { | ||
settings = { | ||
sides: options | ||
}; | ||
} else { | ||
settings = options || {}; | ||
@@ -98,4 +101,3 @@ } | ||
return (elemBoundingRect.top >= config.top); | ||
} | ||
else { | ||
} else { | ||
return (elemBoundingRect.top >= containerScrollTop - (containerScrollTop - containerBoundingRect.top) + config.top); | ||
@@ -111,4 +113,3 @@ } | ||
return (elemBoundingRect.right <= (containerBoundingRect.right + containerScrollLeft) - config.right); | ||
} | ||
else { | ||
} else { | ||
return (elemBoundingRect.right <= containerBoundingRect.right - scrollBarWidths[0] - config.right); | ||
@@ -125,8 +126,6 @@ } | ||
containerHeight = config.container.innerHeight; | ||
} | ||
else if (document && document.documentElement) { | ||
} else if (document && document.documentElement) { | ||
containerHeight = document.documentElement.clientHeight; | ||
} | ||
} | ||
else { | ||
} else { | ||
containerHeight = containerBoundingRect.bottom; | ||
@@ -143,4 +142,3 @@ } | ||
return (elemBoundingRect.left >= config.left); | ||
} | ||
else { | ||
} else { | ||
return (elemBoundingRect.left >= containerScrollLeft - (containerScrollLeft - containerBoundingRect.left) + config.left); | ||
@@ -168,4 +166,3 @@ } | ||
containerScrollLeft = window.scrollX || document.body.scrollLeft; | ||
} | ||
else { | ||
} else { | ||
containerBoundingRect = config.container.getBoundingClientRect(); | ||
@@ -198,4 +195,3 @@ containerScrollTop = config.container.scrollTop; | ||
result = true; | ||
} | ||
else { | ||
} else { | ||
result = false; | ||
@@ -202,0 +198,0 @@ |
Sorry, the diff of this file is not supported yet
21472
343
5