Skip to content

Commit 6be25be

Browse files
committed
🏷️ Update index.d.ts #54
1 parent 73e62f5 commit 6be25be

File tree

6 files changed

+28
-41
lines changed

6 files changed

+28
-41
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ scale | Number | 1.3 | need to be above 1
9797
overflow | Boolean | false |
9898
delay | Number | 0 | the delay is in second **Watch out, sometimes this delay is causing issue on iOS devices [#47](https://github.com/geosigno/simpleParallax.js/issues/47)**
9999
transition | String | '' | any CSS transition
100-
customContainer | String or Node | false |
101-
customWrapper | string | '' | the selector of the custom wrapper
100+
customContainer | String or Node | '' |
101+
customWrapper | String | '' | the selector of the custom wrapper
102102
maxTransition | Number | 0 | it should be a percentage between 1 and 99
103103

104104
You can apply these settings with the following JS code:
@@ -133,7 +133,7 @@ The *transition* setting works closely with the *delay* setting. This setting wi
133133
### customContainer - *String or Node*
134134
By default, the parallax calculation is done with the body scroll percentage. In some cases, the images may be in a container that has its own scroll area, so to have an accurate calculation, the custom container should be set.
135135

136-
### customWrapper - *string*
136+
### customWrapper - *String*
137137
In some cases, you want to use your own wrapper instead of the one created by the plugin. If you specify your custom wrapper, the plugin will add the "simpleParallax" class along with an "overflow: hidden" style.
138138

139139
### maxTransition - *Number* - see [example](https://simpleparallax.com#example-max-transition)

dist/simpleParallax.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images or videos,
3-
* @date: 09-06-2020 12:9:37,
3+
* @date: 21-06-2020 13:22:47,
44
* @version: 5.5.1,
55
* @link: https://simpleparallax.com/
66
*/
@@ -258,7 +258,8 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
258258
this.isVisible = true;
259259
this.isInit = false;
260260
this.oldTranslateValue = -1;
261-
this.init = this.init.bind(this); // check if images has not been loaded yet
261+
this.init = this.init.bind(this);
262+
this.customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper) ? this.element.closest(this.settings.customWrapper) : null; // check if images has not been loaded yet
262263

263264
if (helpers_isImageLoaded(element)) {
264265
this.init();
@@ -322,22 +323,16 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
322323
}, {
323324
key: "wrapElement",
324325
value: function wrapElement() {
325-
// get the customWrapper if any
326-
var customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper); // check is current image is in a <picture> tag
327-
326+
// check is current image is in a <picture> tag
328327
var elementToWrap = this.element.closest('picture') || this.element; // create a .simpleParallax wrapper container
329-
330-
var wrapper = document.createElement('div'); // if there is a custom wrapper
328+
// if there is a custom wrapper
331329
// override the wrapper with it
332330

333-
if (customWrapper) {
334-
wrapper = this.element.closest(this.settings.customWrapper);
335-
}
336-
331+
var wrapper = this.customWrapper || document.createElement('div');
337332
wrapper.classList.add('simpleParallax');
338333
wrapper.style.overflow = 'hidden'; // append the image inside the new wrapper
339334

340-
if (!customWrapper) {
335+
if (!this.customWrapper) {
341336
elementToWrap.parentNode.insertBefore(wrapper, elementToWrap);
342337
wrapper.appendChild(elementToWrap);
343338
}
@@ -348,11 +343,9 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
348343
}, {
349344
key: "unWrapElement",
350345
value: function unWrapElement() {
351-
var wrapper = this.elementContainer; // get the customWrapper if any
352-
353-
var customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper); // if there is a custom wrapper, we jusy need to remove the class and style
346+
var wrapper = this.elementContainer; // if there is a custom wrapper, we jusy need to remove the class and style
354347

355-
if (customWrapper) {
348+
if (this.customWrapper) {
356349
wrapper.classList.remove('simpleParallax');
357350
wrapper.style.overflow = '';
358351
} else {
@@ -589,8 +582,8 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
589582
scale: 1.3,
590583
overflow: false,
591584
transition: 'cubic-bezier(0,0,0,1)',
592-
customContainer: false,
593-
customWrapper: false,
585+
customContainer: '',
586+
customWrapper: '',
594587
maxTransition: 0
595588
};
596589
this.settings = Object.assign(this.defaults, options);

dist/simpleParallax.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ declare module 'simple-parallax-js' {
66
delay?: number;
77
transition?: string;
88
breakpoint?: number;
9-
customContainer?: boolean;
10-
customWrapper?: boolean;
9+
customContainer?: string | HTMLElement;
10+
customWrapper?: string;
1111
maxTransition?: number;
12-
1312
}
1413

1514
export default class SimpleParallax {

src/instances/parallax.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class ParallaxInstance {
1414

1515
this.init = this.init.bind(this);
1616

17+
this.customWrapper =
18+
this.settings.customWrapper && this.element.closest(this.settings.customWrapper)
19+
? this.element.closest(this.settings.customWrapper)
20+
: null;
21+
1722
// check if images has not been loaded yet
1823
if (isImageLoaded(element)) {
1924
this.init();
@@ -77,26 +82,19 @@ class ParallaxInstance {
7782
// if overflow option is set to false
7883
// wrap the element into a .simpleParallax div and apply overflow hidden to hide the image excedant (result of the scale)
7984
wrapElement() {
80-
// get the customWrapper if any
81-
const customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper);
82-
8385
// check is current image is in a <picture> tag
8486
const elementToWrap = this.element.closest('picture') || this.element;
8587

8688
// create a .simpleParallax wrapper container
87-
let wrapper = document.createElement('div');
88-
8989
// if there is a custom wrapper
9090
// override the wrapper with it
91-
if (customWrapper) {
92-
wrapper = this.element.closest(this.settings.customWrapper);
93-
}
91+
let wrapper = this.customWrapper || document.createElement('div');
9492

9593
wrapper.classList.add('simpleParallax');
9694
wrapper.style.overflow = 'hidden';
9795

9896
// append the image inside the new wrapper
99-
if (!customWrapper) {
97+
if (!this.customWrapper) {
10098
elementToWrap.parentNode.insertBefore(wrapper, elementToWrap);
10199
wrapper.appendChild(elementToWrap);
102100
}
@@ -108,11 +106,8 @@ class ParallaxInstance {
108106
unWrapElement() {
109107
const wrapper = this.elementContainer;
110108

111-
// get the customWrapper if any
112-
const customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper);
113-
114109
// if there is a custom wrapper, we jusy need to remove the class and style
115-
if (customWrapper) {
110+
if (this.customWrapper) {
116111
wrapper.classList.remove('simpleParallax');
117112
wrapper.style.overflow = '';
118113
} else {

src/simpleParallax.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export default class SimpleParallax {
2323
scale: 1.3,
2424
overflow: false,
2525
transition: 'cubic-bezier(0,0,0,1)',
26-
customContainer: false,
27-
customWrapper: false,
26+
customContainer: '',
27+
customWrapper: '',
2828
maxTransition: 0
2929
};
3030

0 commit comments

Comments
 (0)