Skip to content

Commit 53541e5

Browse files
committed
Add fade effect for swipeClose
1 parent 0172fd3 commit 53541e5

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

dist/js/parvus.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Parvus
33
*
44
* @author de Oostfreese
5-
* @version 1.0.1
5+
* @version 1.1.0
66
* @url https://github.com/deoostfreese/parvus
77
*
88
* MIT license
@@ -23,6 +23,7 @@
2323
let config = {};
2424
let lightbox = null;
2525
let lightboxOverlay = null;
26+
let lightboxOverlayOpacity = 0;
2627
let lightboxImageContainer = null;
2728
let lightboxImage = null;
2829
let widthDifference;
@@ -256,7 +257,7 @@
256257
heightDifference = THUMBNAIL_SIZE.height / LIGHTBOX_IMAGE_SIZE.height;
257258
xDifference = THUMBNAIL_SIZE.left - LIGHTBOX_IMAGE_SIZE.left;
258259
yDifference = THUMBNAIL_SIZE.top - LIGHTBOX_IMAGE_SIZE.top;
259-
lightboxImageContainer.style.opacity = '1';
260+
lightboxImageContainer.style.opacity = 1;
260261
requestAnimationFrame(() => {
261262
lightboxImage.style.transform = `translate(${xDifference}px, ${yDifference}px) scale(${widthDifference}, ${heightDifference})`;
262263
lightboxImage.style.transition = 'transform 0s'; // Animate the difference reversal on the next tick
@@ -277,6 +278,7 @@
277278

278279

279280
const clearDrag = function clearDrag() {
281+
lightboxOverlay.style.opacity = 1;
280282
lightboxImageContainer.style.transform = 'translate3d(0, 0, 0)';
281283
drag = {
282284
startY: 0,
@@ -422,6 +424,11 @@
422424

423425
const doSwipe = function doSwipe() {
424426
if (Math.abs(drag.startY - drag.endY) > 0 && config.swipeClose) {
427+
if (Math.abs(drag.startY - drag.endY) >= 0 && Math.abs(drag.startY - drag.endY) <= 100) {
428+
lightboxOverlayOpacity = 1 - Math.round(drag.startY - drag.endY) / 100;
429+
}
430+
431+
lightboxOverlay.style.opacity = lightboxOverlayOpacity;
425432
lightboxImageContainer.style.transform = `translate3d(0, -${Math.round(drag.startY - drag.endY)}px, 0)`;
426433
isDraggingY = true;
427434
}

dist/js/parvus.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.

src/js/parvus.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function parvus (userOptions) {
1111
let config = {}
1212
let lightbox = null
1313
let lightboxOverlay = null
14+
let lightboxOverlayOpacity = 0
1415
let lightboxImageContainer = null
1516
let lightboxImage = null
1617
let widthDifference
@@ -272,7 +273,7 @@ export default function parvus (userOptions) {
272273
xDifference = THUMBNAIL_SIZE.left - LIGHTBOX_IMAGE_SIZE.left
273274
yDifference = THUMBNAIL_SIZE.top - LIGHTBOX_IMAGE_SIZE.top
274275

275-
lightboxImageContainer.style.opacity = '1'
276+
lightboxImageContainer.style.opacity = 1
276277

277278
requestAnimationFrame(() => {
278279
lightboxImage.style.transform = `translate(${xDifference}px, ${yDifference}px) scale(${widthDifference}, ${heightDifference})`
@@ -295,6 +296,7 @@ export default function parvus (userOptions) {
295296
*
296297
*/
297298
const clearDrag = function clearDrag () {
299+
lightboxOverlay.style.opacity = 1
298300
lightboxImageContainer.style.transform = 'translate3d(0, 0, 0)'
299301

300302
drag = {
@@ -445,6 +447,11 @@ export default function parvus (userOptions) {
445447
*/
446448
const doSwipe = function doSwipe () {
447449
if (Math.abs(drag.startY - drag.endY) > 0 && config.swipeClose) {
450+
if (Math.abs(drag.startY - drag.endY) >= 0 && Math.abs(drag.startY - drag.endY) <= 100) {
451+
lightboxOverlayOpacity = 1 - (Math.round(drag.startY - drag.endY) / 100)
452+
}
453+
454+
lightboxOverlay.style.opacity = lightboxOverlayOpacity
448455
lightboxImageContainer.style.transform = `translate3d(0, -${Math.round(drag.startY - drag.endY)}px, 0)`
449456

450457
isDraggingY = true

0 commit comments

Comments
 (0)