Skip to content

Commit e9302fd

Browse files
committed
⚡ new React and TypeSript version
1 parent 67d6105 commit e9302fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+9101
-15807
lines changed

.DS_Store

6 KB
Binary file not shown.

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.browserslistrc

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
node_modules/
2-
dist/index\.html
3-
4-
dist/test\.js
5-
6-
package-lock\.json
7-
8-
dist/index\.js
1+
dist
2+
node_modules
3+
dist

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.prettierrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 geosenna
3+
Copyright (c) 2024 Geoffrey Signorato
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
![simpleParallax logo](https://simpleparallax.b-cdn.net/images/logo.png?new=new)
22

3-
[![GitHub version](https://badge.fury.io/gh/geosenna%2FsimpleParallax.svg)](https://badge.fury.io/gh/geosenna%2FsimpleParallax) [![Only 32 Kb](https://badge-size.herokuapp.com/geosigno/simpleParallax.js/master/dist/simpleParallax.min.js)](https://github.com/geosigno/simpleParallax.js/blob/master/strapdown.min.js) [![](https://img.shields.io/npm/dm/simple-parallax-js)](https://www.npmjs.com/package/simple-parallax-js) [![GitHub issues](https://img.shields.io/github/issues/geosigno/simpleParallax.js.svg)](https://GitHub.com/geosigno/simpleParallax.js/issues/) [![](https://data.jsdelivr.com/v1/package/npm/simple-parallax-js/badge?style=rounded)](https://www.jsdelivr.com/package/npm/simple-parallax-js) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
3+
[![GitHub version](https://badge.fury.io/gh/geosenna%2FsimpleParallax.svg)](https://badge.fury.io/gh/geosenna%2FsimpleParallax) [![](https://img.shields.io/npm/dm/simple-parallax-js)](https://www.npmjs.com/package/simple-parallax-js) [![GitHub issues](https://img.shields.io/github/issues/geosigno/simpleParallax.js.svg)](https://GitHub.com/geosigno/simpleParallax.js/issues/) [![](https://data.jsdelivr.com/v1/package/npm/simple-parallax-js/badge?style=rounded)](https://www.jsdelivr.com/package/npm/simple-parallax-js)
44

55
# simpleParallax.js
66

7-
simpleParallax.js is a very simple and tiny Vanilla JS library that adds parallax animations on any images.
7+
simpleParallax.js is a lightweight and easy-to-use React and JS library that adds parallax animations to any image.
88

9-
Where it may be laborious to get results through other plugins, simpleParallax.js stands out for its ease and its visual rendering. The parallax effect is directly applied to image tags, there is no need to use background images. More info on the case study [here](https://medium.com/@geoffrey.signorato/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-35b8daf81471).
10-
11-
Any image will fit. Try it out!
9+
While other plugins can be complex, simpleParallax.js is notable for its simplicity and impressive visual effects. The parallax effect is applied directly to image tags, eliminating the need for background images. Any image can be used. More info on the case study [here](https://medium.com/@geoffrey.signorato/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-35b8daf81471).
1210

11+
Give it a try!
1312

1413
## Installation
1514

16-
### Old way
17-
18-
Simply copy/paste the below snippet just before your closing `</body>` tag :
19-
20-
```html
21-
<script src="simpleParallax.js"></script>
22-
```
23-
24-
or use the below CDN link provided by [jsDelivr.com](https://www.jsdelivr.com/package/npm/simple-parallax-js) :
25-
26-
```html
27-
<script src="https://cdn.jsdelivr.net/npm/simple-parallax-js@5.6.1/dist/simpleParallax.min.js"></script>
28-
```
29-
30-
### Via [npm/yarn](https://www.npmjs.com/package/simple-parallax-js)
31-
32-
You can also install it via :
15+
Install the package via npm or yarn:
3316

3417
```sh
3518
#npm
@@ -39,18 +22,35 @@ npm install simple-parallax-js
3922
yarn add simple-parallax-js
4023
```
4124

42-
and then import it as follows :
25+
Import it:
4326

4427
```javascript
45-
//ES6 import
46-
import simpleParallax from 'simple-parallax-js';
28+
//React version
29+
import SimpleParallax from 'simple-parallax-js';
4730

48-
//CommonJS
49-
const simpleParallax = require('simple-parallax-js');
31+
//Vanilla Version
32+
import SimpleParallax from "simple-parallax-js/vanilla";
5033
```
5134

5235
## Initialization
5336

37+
### React
38+
39+
Simply add the following JavaScript code:
40+
41+
```javascript
42+
43+
import SimpleParallax from "simple-parallax-js";
44+
45+
const Component = () => (
46+
<SimpleParallax>
47+
<img src={"thumbnail.jpg"} alt={"image"} />
48+
</SimpleParallax>
49+
)
50+
51+
```
52+
### Vanilla
53+
5454
Giving the following HTML :
5555

5656
```html
@@ -64,10 +64,6 @@ const image = document.getElementsByClassName('thumbnail');
6464
new simpleParallax(image);
6565
```
6666

67-
and voilà!
68-
69-
___
70-
7167
You can also choose to apply the parallax on multiple images :
7268

7369
```javascript
@@ -99,12 +95,51 @@ scale | Number | 1.3 | need to be above 1
9995
overflow | Boolean | false |
10096
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)**
10197
transition | String | '' | any CSS transition
102-
customContainer | String or Node | '' |
103-
customWrapper | String | '' | the selector of the custom wrapper
10498
maxTransition | Number | 0 | it should be a percentage between 1 and 99
99+
customContainer | String or Node | '' | (Vanilla version only)
100+
customWrapper | String | '' | the selector of the custom wrapper (Vanilla version only)
105101

106102
You can apply these settings with the following JS code :
107103

104+
### React
105+
106+
```javascript
107+
import SimpleParallax from "simple-parallax-js";
108+
109+
const Component = () => (
110+
<SimpleParallax
111+
delay={0}
112+
orientation={"down"}
113+
scale={1.3}
114+
overflow
115+
maxTransition={60}
116+
>
117+
<img src={"thumbnail.jpg"} alt={"image"} />
118+
</SimpleParallax>
119+
)
120+
```
121+
122+
### Next
123+
124+
```javascript
125+
import SimpleParallax from "simple-parallax-js";
126+
import Image from "next/image";
127+
128+
const Component = () => (
129+
<SimpleParallax
130+
delay={0}
131+
orientation={"down"}
132+
scale={1.3}
133+
overflow
134+
maxTransition={60}
135+
>
136+
<Image src={"thumbnail.jpg"} alt={"image"} width={1920} height={1024} />
137+
</SimpleParallax>
138+
)
139+
```
140+
141+
### Vanilla
142+
108143
```javascript
109144
var images = document.querySelectorAll('.thumbnail');
110145
new simpleParallax(images, {
@@ -118,28 +153,31 @@ new simpleParallax(images, {
118153
```
119154

120155
### orientation - *String* - see [example](https://simpleparallax.com#example-orientation)
121-
This is the orientation (or direction) of the parallax effect. Choose *up* and when scrolling down, the image will translate from the bottom to the top (so the image will translate up). When scrolling up, the image will translate from the top to the bottom. Same logic applies for all others orientations (*right*, *down*, *left*, *up left*, *up right*, *down left* or *down right*). When 2 directions are combined (for example *down right*), the image will translate diagonally.
156+
The parallax effect's orientation, or direction, can be customized. If you choose *up*, the image will move from bottom to top as you scroll down, and from top to bottom as you scroll up. This same logic applies for all other orientations, including *right*, *down*, *left*, *up left*, *up right*, *down left*, and *down right*. If two directions are combined, such as *down right*, the image will move diagonally.
122157

123158
### scale - *Number* - see [example](https://simpleparallax.com#example-scale)
124-
The higher the scale is set, the more visible the parallax effect will be. In return, the image will lose in quality. To reduce the lossless effect, if the scale is set at 1.5 and your image is 500px width, do the simple math 500 * 1.5 = 750. So you can choose a 750px image to replace your 500px one, and don't see any quality leak. More information is available if you read the case study [here](https://medium.com/@geoffrey.signorato/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-35b8daf81471).
159+
The higher the *scale* setting, the more pronounced the parallax effect becomes. However, this can cause the image quality to diminish. To mitigate this, if the *scale* is set at 1.5 and your image width is 500px, simply multiply 500 by 1.5 to get 750. You can then use a 750px image in place of your 500px one to maintain image quality. More information can be found in the case study linked [here](https://medium.com/@geoffrey.signorato/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-35b8daf81471).
125160

126161
### overflow - *Boolean* - see [example](https://simpleparallax.com#example-overflow)
127-
By default, the image is scaled to apply a parallax effect without any overflow on the layout - you can check the [case study](https://medium.com/@geoffrey.signorato/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-35b8daf81471) to have a better understanding. When *overflow* is set to true, the image will translate out of its natural flow (so it may overlap with your content).
162+
By default, the image scales to create a parallax effect without any overflow on the layout - for a better understanding, review the [case study](https://medium.com/@geoffrey.signorato/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-35b8daf81471). When overflow is set to true, the image will translate beyond its natural flow, potentially overlapping your content.
128163

129164
### delay - *Number* - see [example](https://simpleparallax.com#example-delay-transition)
130-
When a *delay* is set, the translation of the image will continue during that delay when the user stops scrolling. That gives a very nice effect. 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)**
165+
Setting a delay prolongs the image's translation even after the user has stopped scrolling, creating a pleasing effect. This delay is measured in seconds. **Watch out, sometimes this delay is causing issue on iOS devices [#47](https://github.com/geosigno/simpleParallax.js/issues/47)**
131166

132167
### transition - *String* - see [example](https://simpleparallax.com#example-delay-transition)
133-
The *transition* setting works closely with the *delay* setting. This setting will add any CSS transition to the delay setting. For example, you can use *ease* or *ease-in-out*.
168+
The transition setting is linked with the delay setting. It applies any CSS transition to the delay setting, such as ease or ease-in-out.
169+
170+
### maxTransition - *Number* - see [example](https://simpleparallax.com#example-max-transition)
171+
The maxTransition setting controls the extent of the parallax animation. By default, it translates from 0% to 100% of the user's viewport. You can adjust this to any percentage.
134172

135-
### customContainer - *String or Node*
136-
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.
173+
### src - *String* - Vanilla version only
174+
This is the source of the image. It can be a local path or a URL.
137175

138-
### customWrapper - *String*
139-
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.
176+
### customContainer - *String or Node* - Vanilla version only
177+
Parallax calculations default to the body scroll percentage. However, images may be in a container with its own scroll area. For accurate calculations, set a custom container.
140178

141-
### maxTransition - *Number* - see [example](https://simpleparallax.com#example-max-transition)
142-
The maxTransition setting should be used to stop the parallax animation after a given percentage. By default, it translates from 0% to 100% of the user viewport. You can change it here to any percentage you want.
179+
### customWrapper - *String* - Vanilla version only
180+
In some instances, you might want to use your own wrapper instead of the plugin's. Specifying a custom wrapper will add the simpleParallax class and an overflow: hidden style.
143181

144182
## Methods
145183

0 commit comments

Comments
 (0)