@kizmann/pico-js 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pico-js.js +1 -1
- package/dist/pico-js.js.map +1 -1
- package/package.json +1 -1
- package/src/utility/dom.js +50 -0
package/package.json
CHANGED
package/src/utility/dom.js
CHANGED
@@ -133,6 +133,27 @@ export class Dom
|
|
133
133
|
return this.get(0) && this.get(0).is(':visible');
|
134
134
|
}
|
135
135
|
|
136
|
+
inviewHeight()
|
137
|
+
{
|
138
|
+
let viewport = {
|
139
|
+
width: Dom.find(window).width(),
|
140
|
+
height: Dom.find(window).height(),
|
141
|
+
};
|
142
|
+
|
143
|
+
let element = {
|
144
|
+
width: this.width(),
|
145
|
+
height: this.height(),
|
146
|
+
};
|
147
|
+
|
148
|
+
let scroll = this.scroll(),
|
149
|
+
offset = this.offset();
|
150
|
+
|
151
|
+
let bottom = offset.top + element.height;
|
152
|
+
|
153
|
+
return Math.max(0, Math.min(bottom, viewport.height + scroll.top) -
|
154
|
+
Math.max(offset.top, scroll.top))
|
155
|
+
}
|
156
|
+
|
136
157
|
inviewX(ratio = 0)
|
137
158
|
{
|
138
159
|
let viewport = {
|
@@ -181,6 +202,35 @@ export class Dom
|
|
181
202
|
return top <= scroll.top && scroll.top <= bottom;
|
182
203
|
}
|
183
204
|
|
205
|
+
static inviewMaxY(selector, callback = null, context = null)
|
206
|
+
{
|
207
|
+
let [items, attr] = [
|
208
|
+
[], selector.replace(/^\[([^="]+)]$/, '$1')
|
209
|
+
];
|
210
|
+
|
211
|
+
let parent = Dom.find(selector);
|
212
|
+
|
213
|
+
if ( ! Any.isNull(context) ) {
|
214
|
+
parent = Dom.find(context);
|
215
|
+
}
|
216
|
+
|
217
|
+
parent.each((el) => {
|
218
|
+
items.push({ el, height: Dom.find(el).inviewHeight() });
|
219
|
+
});
|
220
|
+
|
221
|
+
let heights = Arr.extract(items, 'height');
|
222
|
+
|
223
|
+
let el = Arr.find(items, (item) => {
|
224
|
+
return item.height === Math.max(...heights);
|
225
|
+
});
|
226
|
+
|
227
|
+
if ( ! Any.isEmpty(el) && Any.isFunction(callback) ) {
|
228
|
+
callback.call({}, el.el, el.el.getAttribute(attr));
|
229
|
+
}
|
230
|
+
|
231
|
+
return el.el;
|
232
|
+
}
|
233
|
+
|
184
234
|
is(selector)
|
185
235
|
{
|
186
236
|
return this.matches(selector);
|