@kizmann/pico-js 1.0.11 → 1.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -133,11 +133,13 @@ export class Dom
133
133
  return this.get(0) && this.get(0).is(':visible');
134
134
  }
135
135
 
136
- inviewHeight()
136
+ inviewHeight(boundry = window)
137
137
  {
138
+ let parent = Dom.find(boundry);
139
+
138
140
  let viewport = {
139
- width: Dom.find(window).width(),
140
- height: Dom.find(window).height(),
141
+ width: parent.width(),
142
+ height: parent.height(),
141
143
  };
142
144
 
143
145
  let element = {
@@ -148,10 +150,12 @@ export class Dom
148
150
  let scroll = this.scroll(),
149
151
  offset = this.offset();
150
152
 
151
- let bottom = offset.top + element.height;
153
+ let [top, bottom] = [
154
+ scroll.top + parent.offset('top'), offset.top + element.height
155
+ ];
152
156
 
153
- return Math.max(0, Math.min(bottom, viewport.height + scroll.top) -
154
- Math.max(offset.top, scroll.top))
157
+ return Math.max(0, Math.min(bottom, viewport.height + top) -
158
+ Math.max(offset.top, top))
155
159
  }
156
160
 
157
161
  inviewX(ratio = 0)
@@ -212,10 +216,13 @@ export class Dom
212
216
  options = { el: options };
213
217
  }
214
218
 
219
+ let boundry = Dom.find(options.parent)
220
+ .closestScrollable(window);
221
+
215
222
  options = Obj.assign({}, defaults, options);
216
223
 
217
224
  let safeback = (item) => {
218
- return Math.min(Dom.find(item.el).height() * 0.5, Dom.find(window).height() * 0.2);
225
+ return Math.min(Dom.find(item.el).height() * 0.5, Dom.find(boundry).height() * 0.2);
219
226
  };
220
227
 
221
228
  let safezone = options.safezone;
@@ -236,7 +243,7 @@ export class Dom
236
243
 
237
244
  parent.each((el) => {
238
245
  items.push({
239
- el, attr: Dom.find(el).attr(attr), height: Dom.find(el).inviewHeight()
246
+ el, attr: Dom.find(el).attr(attr), height: Dom.find(el).inviewHeight(boundry)
240
247
  });
241
248
  });
242
249
 
@@ -245,7 +252,7 @@ export class Dom
245
252
  });
246
253
 
247
254
  results = Arr.sort(results, (a, b) => {
248
- return a.height > b.height ? -1 : 1;
255
+ return a.height >= b.height ? -1 : 1;
249
256
  });
250
257
 
251
258
  Arr.each(results, (item, index) => {
@@ -438,6 +445,10 @@ export class Dom
438
445
  return Dom.find(null);
439
446
  }
440
447
 
448
+ if ( el instanceof Window ) {
449
+ el = document;
450
+ }
451
+
441
452
  let nodes = el.querySelectorAll(selector);
442
453
 
443
454
  nodes = Array.prototype.slice.call(nodes);