@cocreate/scroll 1.3.2 → 1.3.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [1.3.5](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.3.4...v1.3.5) (2022-06-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed scroll-element support as it was causing a loop. Moved to branch newScroll fordebugging ([f8d99c7](https://github.com/CoCreate-app/CoCreate-scroll/commit/f8d99c707b0e87032f7dd547b3342d308182c6d6))
7
+
8
+ ## [1.3.4](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.3.3...v1.3.4) (2022-06-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump dependencies ([0bd768f](https://github.com/CoCreate-app/CoCreate-scroll/commit/0bd768fb982758e6daa62bfd3724a3dec1618f88))
14
+
15
+ ## [1.3.3](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.3.2...v1.3.3) (2022-06-18)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * fix scroll event loop ([59f6998](https://github.com/CoCreate-app/CoCreate-scroll/commit/59f6998d5c4f562584efa3b64793381a3e49ebe6))
21
+
1
22
  ## [1.3.2](https://github.com/CoCreate-app/CoCreate-scroll/compare/v1.3.1...v1.3.2) (2022-06-17)
2
23
 
3
24
 
package/demo/index.html CHANGED
@@ -40,7 +40,7 @@
40
40
  }
41
41
 
42
42
  .scrolling {
43
- background-color: gray;
43
+ background-color: rgb(226, 31, 210);
44
44
  }
45
45
 
46
46
 
@@ -62,13 +62,12 @@
62
62
  <!-- Navbar -->
63
63
  <div class="display:flex flex-wrap:wrap justify-content:space-between flex-direction:row padding-top:10px padding-bottom:10px width:100% nav"
64
64
  content_id="content"
65
- scroll="hidden, sticky-nav"
66
- scrolling="scrolling"
67
65
  scroll-top="scroll_top"
68
- scroll-limbo="scroll_limbo"
69
66
  scroll-bottom="scroll_bottom"
67
+ scroll="hidden, sticky-nav"
70
68
  scroll-up="10"
71
- scroll-down="5">
69
+ scroll-down="5"
70
+ >
72
71
 
73
72
  <!--<a href="#" class="logo">Navbar</a>-->
74
73
  <div class="margin:0px_15px display:flex flex-wrap:wrap justify-content:space-between flex-direction:row align-items:center width:100%">
@@ -106,7 +105,7 @@
106
105
  </div>
107
106
  </div>
108
107
  </div>
109
- <section class="padding-top:80px padding-bottom:40px ">
108
+ <section class="padding-top:80px padding-bottom:40px" scroll scrolling="scrolling">
110
109
  <div class=" max-width:90% margin:0px_auto">
111
110
  <div class="display:flex flex-wrap:wrap align-items:center flex-direction:row-reverse">
112
111
  <div class="flex-grow:1 min-width:300px width:50%">
@@ -122,7 +121,7 @@
122
121
  </div>
123
122
  </div>
124
123
  </section>
125
- <section class="bg-light-gray padding:25px_0px">
124
+ <section class="bg-light-gray padding:25px_0px" scroll scroll-limbo="scroll_limbo">
126
125
  <div class="max-width:90% margin:0px_auto">
127
126
  <div class="padding:25px_0px display:flex flex-wrap:wrap justify-content:space-between flex-direction:row align-items:center">
128
127
  <div class="padding:0px_10px">
@@ -227,7 +226,6 @@
227
226
  </div>
228
227
 
229
228
 
230
- <!--<script src="../dist/CoCreate-selected.js"></script>-->
231
229
  <script src="../../../CoCreateJS/dist/CoCreate.js" ></script>
232
230
 
233
231
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/scroll",
3
- "version": "1.3.2",
3
+ "version": "1.3.5",
4
4
  "description": "A simple scroll component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "scroll",
@@ -61,7 +61,7 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.3.2",
65
- "@cocreate/observer": "^1.5.2"
64
+ "@cocreate/docs": "^1.3.3",
65
+ "@cocreate/observer": "^1.5.3"
66
66
  }
67
67
  }
package/src/index.js CHANGED
@@ -3,8 +3,6 @@ import observer from '@cocreate/observer';
3
3
  const CoCreateScroll = {
4
4
  delta: 3,
5
5
  observer: null,
6
- elementList: new Map(),
7
-
8
6
  init: function() {
9
7
  let elements = document.querySelectorAll(`[scroll]`);
10
8
  this.__initIntersectionObserver();
@@ -22,7 +20,6 @@ const CoCreateScroll = {
22
20
  const downSize = this.__getSize(element.getAttribute('scroll-down'));
23
21
  const attrName = element.getAttribute('scroll-attribute') || 'class';
24
22
  const targetSelector = element.getAttribute('scroll-target');
25
- const scrollSelector = element.getAttribute('scroll-element');
26
23
  const intersectValue = element.getAttribute('scroll-intersect');
27
24
 
28
25
  let values = element.getAttribute('scroll') || "";
@@ -50,49 +47,31 @@ const CoCreateScroll = {
50
47
 
51
48
  this.__runScrollEvent(element, scrollInfo);
52
49
 
53
- let scrollableElements;
54
- if (scrollSelector)
55
- scrollableElements = document.querySelectorAll(scrollSelector);
56
-
57
- if (scrollableElements) {
58
- for (let scrollableEl of scrollableElements)
59
- scrollableEl.addEventListener('scroll', function(event) {
60
- self._scrollEvent(elements, element, scrollInfo, scrollableEl)
61
- });
62
- } else {
63
- window.addEventListener('scroll', function(event) {
64
- self._scrollEvent(elements, element, scrollInfo)
65
- });
66
- }
67
-
68
- if (intersectValue && window.IntersectionObserver && this.observer) {
69
- this.observer.observe(element);
70
- }
71
- },
72
-
73
- _scrollEvent: function(elements, element, scrollInfo, scrollableEl) {
74
- const self = this;
75
- if (!element.scrollStatus) return;
76
- let scrollEl = scrollableEl || window;
77
- if (Math.abs(scrollEl.scrollTop || scrollEl.scrollY - element.scrollStatus.currentPos) <= self.delta) {
78
- return;
79
- }
80
-
81
50
  let timer = null;
82
- if (timer != null) {
83
- clearTimeout(timer);
84
- }
51
+ window.addEventListener('scroll', function(event) {
52
+ if (!element.scrollStatus) return;
53
+ if (Math.abs(window.scrollY - element.scrollStatus.currentPos) <= self.delta) {
54
+ return;
55
+ }
85
56
 
86
- elements.forEach((el) => {
87
- self.__runScrollEvent(el, scrollInfo, scrollableEl);
88
- self.__setScrolling(el, scrollInfo, false);
89
- });
57
+ if (timer != null) {
58
+ clearTimeout(timer);
59
+ }
90
60
 
91
- timer = setTimeout(function() {
92
61
  elements.forEach((el) => {
93
- self.__setScrolling(el, scrollInfo, true);
62
+ self.__runScrollEvent(el, scrollInfo);
63
+ self.__setScrolling(el, scrollInfo, false);
94
64
  });
95
- }, 500);
65
+
66
+ timer = setTimeout(function() {
67
+ elements.forEach((el) => {
68
+ self.__setScrolling(el, scrollInfo, true);
69
+ });
70
+ }, 500);
71
+ });
72
+ if (intersectValue && window.IntersectionObserver && this.observer) {
73
+ this.observer.observe(element);
74
+ }
96
75
  },
97
76
 
98
77
  __initIntersectionObserver: function() {
@@ -128,19 +107,10 @@ const CoCreateScroll = {
128
107
  }
129
108
  },
130
109
 
131
- __runScrollEvent: function(element, info, scrollableEl) {
110
+ __runScrollEvent: function(element, info) {
132
111
  if (!element.scrollStatus) return
133
112
  const currentPos = element.scrollStatus.currentPos;
134
- let scrollY, scrollHeight, innerHeight;
135
- if (scrollableEl){
136
- scrollY = scrollableEl.scrollTop;
137
- scrollHeight = scrollableEl.scrollHeight
138
- innerHeight = scrollableEl.clientHeight
139
- } else {
140
- scrollY = window.scrollY;
141
- scrollHeight = document.body.scrollHeight
142
- innerHeight = window.innerHeight
143
- }
113
+ const scrollY = window.scrollY;
144
114
  const { upSize, downSize, attrName, values, scrollTop, scrollBottom, scrollLimbo } = info;
145
115
 
146
116
  if (upSize < (currentPos - scrollY)) {
@@ -164,8 +134,7 @@ const CoCreateScroll = {
164
134
  }
165
135
 
166
136
  //. scroll bottom case
167
- // if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
168
- if ((innerHeight + scrollY) >= scrollHeight) {
137
+ if ((window.innerHeight + scrollY) >= document.body.scrollHeight) {
169
138
  // this.__removeAttrbuteValue(element, attrName, values[0]);
170
139
  // this.__removeAttrbuteValue(element, attrName, values[1]);
171
140
 
@@ -175,8 +144,7 @@ const CoCreateScroll = {
175
144
  this.__removeAttrbuteValue(element, attrName, scrollBottom);
176
145
  }
177
146
 
178
- // if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
179
- if (scrollY != 0 && (scrollY + innerHeight) != scrollHeight){
147
+ if (scrollY != 0 && (scrollY + window.innerHeight) != document.body.scrollHeight){
180
148
  this.__addAttributeValue(element, attrName, scrollLimbo);
181
149
  }
182
150
  else {
@@ -229,6 +197,8 @@ const CoCreateScroll = {
229
197
  return size;
230
198
  }
231
199
 
200
+
201
+
232
202
  };
233
203
 
234
204
  observer.init({
@@ -243,4 +213,4 @@ observer.init({
243
213
 
244
214
  CoCreateScroll.init();
245
215
 
246
- export default CoCreateScroll;
216
+ export default CoCreateScroll;