|
1 | 1 | /** |
2 | 2 | * animated-scroll |
3 | | - * Version: 0.0.1 |
4 | | - * (c) 2016 Joel Mukuthu |
| 3 | + * Version: 0.0.2 |
| 4 | + * (c) 2019 Joel Mukuthu |
5 | 5 | * MIT License |
6 | | - * Built on: 17-11-2016 18:05:38 GMT+0100 |
| 6 | + * Built on: 07-12-2019 12:49:33 GMT+0100 |
7 | 7 | **/ |
8 | 8 |
|
9 | 9 | (function (global, factory) { |
|
105 | 105 |
|
106 | 106 | var validatePositiveNumber = function validatePositiveNumber(number, name) { |
107 | 107 | if (typeof number !== 'number' || isNaN(number)) { |
108 | | - throw new Error(name + ' (' + number + ') should be a number'); |
| 108 | + throw new Error(name + ' should be a number'); |
109 | 109 | } |
110 | 110 | if (number < 0) { |
111 | | - throw new Error(name + ' (' + number + ') should be greater than zero'); |
| 111 | + throw new Error(name + ' should be greater than or equal to zero'); |
112 | 112 | } |
113 | 113 | }; |
114 | 114 |
|
|
118 | 118 |
|
119 | 119 | _classCallCheck(this, AnimatedScroll); |
120 | 120 |
|
| 121 | + if (!element) { |
| 122 | + throw new Error('provide a DOM element'); |
| 123 | + } |
| 124 | + |
121 | 125 | if ((typeof element === 'undefined' ? 'undefined' : _typeof(element)) !== 'object' || typeof element.nodeName !== 'string') { |
122 | 126 | throw new Error('the element should be a DOM element'); |
123 | 127 | } |
|
141 | 145 | } |
142 | 146 |
|
143 | 147 | var easing = options.easing; |
144 | | - if (typeof easing !== 'undefined' && typeof easing !== 'function') { |
145 | | - throw new Error('the easing option should be a function'); |
| 148 | + if (typeof easing !== 'undefined') { |
| 149 | + if (typeof easing !== 'function') { |
| 150 | + throw new Error('the easing option should be a function'); |
| 151 | + } |
| 152 | + this.easing = easing; |
146 | 153 | } else { |
147 | 154 | this.easing = easeInOutQuad; |
148 | 155 | } |
|
160 | 167 | validatePositiveNumber(offset, direction); |
161 | 168 |
|
162 | 169 | if (duration !== false) { |
163 | | - return validatePositiveNumber(duration, 'duration'); |
| 170 | + validatePositiveNumber(duration, 'duration'); |
164 | 171 | } |
165 | 172 | if (typeof easing !== 'function') { |
166 | 173 | throw new Error('easing should be a function'); |
|
175 | 182 | _this.stopTop(); |
176 | 183 | } else { |
177 | 184 | elementProperty = 'scrollLeft'; |
178 | | - animationProperty = 'topAnimation'; |
| 185 | + animationProperty = 'leftAnimation'; |
179 | 186 |
|
180 | 187 | _this.stopLeft(); |
181 | 188 | } |
|
191 | 198 | var change = offset - start; |
192 | 199 | var timeIncrement = _this.timeIncrement; |
193 | 200 |
|
194 | | - duration = parseInt(duration); |
| 201 | + duration = parseInt(duration, 10); // you want to use radix 10 |
| 202 | + // so you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1]) |
195 | 203 |
|
196 | 204 | var currentTime = 0; |
197 | 205 | var animate = function animate() { |
|
214 | 222 | resolve(_this.element[elementProperty]); |
215 | 223 | } |
216 | 224 | }; |
| 225 | + animate(); |
217 | 226 | }); |
218 | 227 | } |
219 | 228 | }, { |
|
0 commit comments