Skip to content

Commit 213843a

Browse files
Merge pull request #32 from tomik23:onResize
OnResize new callback function
2 parents f74553a + 2fd7e3e commit 213843a

13 files changed

Lines changed: 719 additions & 387 deletions

.eslintrc.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,9 @@ module.exports = {
77
extends: ['eslint:recommended', 'prettier'],
88
plugins: ['prettier'],
99
rules: {
10-
'prettier/prettier': [
11-
'warn',
12-
{
13-
semi: true,
14-
singleQuote: true,
15-
tabWidth: 2,
16-
endOfLine: 'auto',
17-
printWidth: 80,
18-
},
19-
],
10+
'prettier/prettier': 'error',
2011
'comma-dangle': ['error', 'only-multiline'],
2112
'linebreak-style': ['error', 'windows'],
2213
'no-param-reassign': [2, { props: false }],
23-
}
14+
},
2415
};

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"endOfLine": "auto",
6+
"printWidth": 80
7+
}

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,79 @@
1+
## v1.0.13 (2021-06-17)
2+
3+
### Added
4+
5+
- callback function `onResize`
6+
7+
### Changed
8+
9+
- callback function, name change from `onCleared` to `onClose` and `onLoaded` to `onOpen`
10+
111
## v1.0.12 (2021-06-13)
12+
213
### Changed
14+
315
- fix: scrollTop not always work [#28](https://github.com/tomik23/zooom.js/issues/28)
416

517
## v1.0.11 (2021-04-16)
18+
619
### Added
20+
721
- New example - leading color
822

923
## v1.0.10 (2021-03-30)
24+
1025
### Added
26+
1127
- Create a separate photo with styles for each click, fixed problem when photo is in overflow element
1228

1329
### Changed
30+
1431
- fix: Fixed problem when photo is in overflow element
1532
- Removal of style from main photo
1633
- Replaced node-sass to sass
1734
- The browserslist extension
1835
- Remove interface ImageParameters
1936

2037
## v1.0.9 (2020-11-20)
38+
2139
### Added
40+
2241
- UMD file
2342
- Renaming a variable
2443
- Banner from rollup.js
2544

2645
### Changed
46+
2747
- Removed banner plugin
2848

2949
## v1.0.8 (2020-09-09)
50+
3051
### Added
52+
3153
- New photos for example
3254
- Adding vertical photos
3355
- Example figure with picture
3456

3557
### Changed
58+
3659
- Removed padding
3760
- Converted to typescript
3861

3962
## v1.0.7 (2020-09-07)
63+
4064
### Changed
65+
4166
- Lightbox animation not always appearing [#15](https://github.com/tomik23/zooom.js/issues/15)
4267

4368
## v1.0.6 (2020-09-06)
69+
4470
### Added
71+
4572
- Debounce to resize window
4673
- Two helpers functions `onLoaded`, `onCleared`
4774
- Changelog.md
4875

4976
### Changed
77+
5078
- Change fade(in/out) from js to css
51-
- Separate style
79+
- Separate style

README.md

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,31 @@
1717
See the demo - [example](https://tomik23.github.io/zooom.js/)
1818

1919
## How to add to page
20+
2021
1. Just download the library from the `docs/zoom.min.js` and add it to head.
22+
2123
```html
2224
<script src="./zooom.min.js"></script>
2325
```
26+
2427
2. For each photo you want to grow, add a class in our example it's `img-zoom`
28+
2529
```html
26-
<img class="img-zoom" src="./images/image.jpg">
30+
<img class="img-zoom" src="./images/image.jpg" />
2731
```
32+
2833
3. Now all you have to do is call our library, this is the simplest example. Below you will find a description of how to configure the library more.
34+
2935
```html
3036
<script>
31-
window.addEventListener('DOMContentLoaded', function() {
37+
window.addEventListener('DOMContentLoaded', function () {
3238
new Zooom('img-zoom');
3339
});
3440
</script>
3541
```
3642

37-
3843
## Clone the repo and install dependencies
44+
3945
```bash
4046
git clone https://github.com/tomik23/zooom.js.git
4147
cd zooom
@@ -45,6 +51,7 @@ npm i
4551
```
4652

4753
## Watch/Build the app
54+
4855
Watch the app, just call:
4956

5057
```bash
@@ -63,95 +70,123 @@ npm run prod
6370

6471
## Configuration of the plugin
6572

66-
props | type | default | require | description
67-
---- | :-------: | :-------: | :--------: | -----------
68-
zIndex | Number | `1` | | Option to control layer positions
69-
animationTime | Number | `300` | | Animation speed in milliseconds
70-
in / out | String | `zoom-in / zoom-out` | | The cursor property specifies the mouse cursor to be displayed when pointing over an element
71-
color | String | `#fff` | | Overlay layer color, hex only
72-
opacity | Number | `100` | | Overlay layer opacity, number must be an integer, maximum number 100
73-
onLoaded | Function | | | A helper function with which we can, for example, add text from the caption to the photo to show when zooming in on the photo. In the function we have access to the image element
74-
onCleared | Function | | | A function that runs when the photo is closed. It can be combined with the function `onLoaded` see example. As in the previous `onLoaded` function, here we have access to the image element
73+
| props | type | default | require | description |
74+
| ------------- | :------: | :------------------: | :-----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
75+
| zIndex | Number | `1` | | Option to control layer positions |
76+
| animationTime | Number | `300` | | Animation speed in milliseconds |
77+
| in / out | String | `zoom-in / zoom-out` | | The cursor property specifies the mouse cursor to be displayed when pointing over an element |
78+
| color | String | `#fff` | | Overlay layer color, hex only |
79+
| opacity | Number | `100` | | Overlay layer opacity, number must be an integer, maximum number 100 |
80+
| onResize | Function | | | A function that can be used to block clicking on an image. See example below - How to prevent zoom-in/out images |
81+
| onOpen | Function | | | A helper function with which we can, for example, add text from the caption to the photo to show when zooming in on the photo. In the function we have access to the image element |
82+
| onClose | Function | | | A function that runs when the photo is closed. It can be combined with the function `onOpen` see example. As in the previous `onOpen` function, here we have access to the image element |
83+
84+
## Minimal configuration
85+
86+
```javascript
87+
new Zooom('img-zoom');
88+
```
7589

7690
## Sample configuration
91+
7792
```javascript
7893
new Zooom('img-zoom', {
7994
zIndex: 9,
80-
95+
8196
// animation time in number
8297
animationTime: 300,
83-
98+
8499
// cursor type
85100
cursor: {
86101
in: 'zoom-in',
87-
out: 'zoom-out'
102+
out: 'zoom-out',
88103
},
89104

90105
overlay: {
91-
92106
// hex or color-name
93107
color: '#fff',
94-
108+
95109
// [10, 20, 34, ..., 100] maximum number 100
96110
opacity: 80,
97111
},
98112

99113
// callback function
100114
// see usage example docs/index.html
101-
onLoaded: function(element) {},
102-
onCleared: function(element) {}
115+
onResize: function () {},
116+
onOpen: function (element) {},
117+
onClose: function (element) {},
103118
});
104119
```
105120

106-
## Minimal configuration
107-
```javascript
108-
new Zooom('img-zoom');
109-
```
110-
111121
## How to use Zooom with Bootstrap Carousel
122+
112123
See an [example](https://codepen.io/Tomik23/full/VwPmLqX)
124+
113125
```javascript
114126
new Zooom('img-zoom', {
115127
zIndex: 9,
116-
128+
117129
// animation time in number
118130
animationTime: 300,
119-
131+
120132
// cursor type
121133
cursor: {
122134
in: 'zoom-in',
123-
out: 'zoom-out'
135+
out: 'zoom-out',
124136
},
125137
overlay: {
126-
127138
// hex or color-name
128139
color: '#fff',
129-
140+
130141
// [10, 20, 34, ..., 100] maximum number 100
131142
opacity: 80,
132143
},
133144

134145
// callback function
135146
// see usage example docs/index.html
136-
onLoaded: function(element) {
137-
147+
onOpen: function (element) {
138148
// we stop automatic scrolling when we do zoom images
139149
$('.carousel').carousel('pause');
140150
},
141-
142-
onCleared: function(element) {
143-
151+
152+
onClose: function (element) {
144153
// we restart the carousels after closing the photo
145154
$('.carousel').carousel('cycle');
146-
}
155+
},
156+
});
157+
```
158+
159+
## How to prevent zoom-in/out images
160+
161+
Below is an example showing how to block a click when the browser width is less than 600px
162+
Of course, here is an example with the width of the window, but nothing prevents you from using it in a different way. The most important thing is to return the logical value - `true/false`. Each `reduction/reduction` of the window reads this variable and blocks the click.
163+
164+
```javascript
165+
new Zooom('img-zoom', {
166+
onResize: function () {
167+
// we set the page width from which it will
168+
// be possible to click on the image
169+
let responsiveMin = 600;
170+
171+
// we check the width of the browser window
172+
const windowWidth =
173+
window.innerWidth ||
174+
document.documentElement.clientWidth ||
175+
document.body.clientWidth;
176+
177+
// we return the boolean value 'true/false'
178+
// the value 'true' blocks clicking the image
179+
return windowWidth < responsiveMin ? true : false;
180+
},
147181
});
148182
```
149183

150184
## Browsers support
151185

152186
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Opera | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/vivaldi/vivaldi_48x48.png" alt="Vivaldi" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br/>Vivaldi |
153-
| --------- | --------- | --------- | --------- | --------- |
154-
| IE10, IE11, Edge| last 2 versions| last 2 versions| last 2 versions| last 2 versions
187+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
188+
| IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
155189

156190
## License
157-
This project is available under the [MIT](https://opensource.org/licenses/mit-license.php) license.
191+
192+
This project is available under the [MIT](https://opensource.org/licenses/mit-license.php) license.

docs/index.html

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,33 @@ <h2>The leading color from the photo</h2>
150150
window.addEventListener('DOMContentLoaded', function () {
151151
new Zooom('img-zoom', {
152152
zIndex: 9,
153-
animationTime: 300, // animation time in number
153+
154+
// animation time in number
155+
animationTime: 300,
156+
154157
cursor: {
155158
in: 'zoom-in',
156159
out: 'zoom-out'
157160
},
161+
158162
overlay: {
159163
// hex or color-name
160164
color: '#fff',
161165
// [10, 20, 34, ..., 100] maximum number 100
162166
opacity: 80,
163167
},
164-
onLoaded: function (element) {
168+
169+
onResize: function () {
170+
let responsiveMin = 600;
171+
const windowWidth =
172+
window.innerWidth ||
173+
document.documentElement.clientWidth ||
174+
document.body.clientWidth;
175+
176+
return windowWidth < responsiveMin ? true : false;
177+
},
178+
179+
onOpening: function (element) {
165180
const nextSibling = element.nextElementSibling ? element.nextElementSibling : element.parentNode.nextElementSibling;
166181
if (nextSibling && nextSibling.classList.contains('description')) {
167182
const textContent = nextSibling.innerHTML;
@@ -181,7 +196,8 @@ <h2>The leading color from the photo</h2>
181196
}
182197
}
183198
},
184-
onCleared: function (element) {
199+
200+
onClosed: function (element) {
185201
const descriptionText = document.getElementById('description');
186202
if (descriptionText) {
187203
descriptionText.classList.remove('animation-on');

docs/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)