Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5-beta - add slide transition with keyboard and click button action? #1765

Open
BilouMaster opened this issue Jun 24, 2021 · 24 comments
Open

Comments

@BilouMaster
Copy link

Hello, marvelous creator of this marvelous creation!

I think it would be perfect if there were a sliding animation when we use pswp with the keyboard or the right/left buttons, for now it jumps instantly to the next or previous image and it's a bit disappointing because I am sure that the core already have what it needs to add a simple sliding animation just like if we swiped it...

Is there a specific reason for the actual lack of transition?

Best regards!

Joke

@BilouMaster BilouMaster changed the title v5 - beta : add slide transition with keyboard and click button action? v5-beta - add slide transition with keyboard and click button action? Jun 24, 2021
@amkdev
Copy link

amkdev commented Jul 18, 2021

I am very much in favor of this!

@acwolff
Copy link

acwolff commented Jul 19, 2021

Yes please implement sliding animations!

@rbndelrio
Copy link

rbndelrio commented Oct 5, 2021

To anyone really wanting this feature, it's technically possible to force it. It seems like dimsemenov has intentions to add this feature but hasn't enabled it for stability. From my testing, it doesn't play well with gallery looping enabled.

Option 1: Fork and modify these lines

goTo(index, animate = false) {
  // ...
  const indexChanged = this.mainScroll.moveIndexBy(index - this.potentialIndex, animate);
  // ...
}

//... next
this.goTo(this.potentialIndex + 1, true);

//... prev
this.goTo(this.potentialIndex - 1, true);
//...

That's enough for my (very temporary) use case.

Option 2: Replacing the method after construction

const lightbox = new PhotoSwipeLightbox({ loop: false });
const customGoTo = (index, animate = false) => {
  const ctx = lightbox.pswp;
  index = ctx.getLoopedIndex(index);
  const indexChanged = ctx.mainScroll.moveIndexBy(index - ctx.potentialIndex, animate);

  if (indexChanged) {
    ctx.dispatch('afterGoto');
  }
}
lightbox.on('uiRegister', () => {
  lightbox.pswp.next = () => customGoTo(lightbox.pswp.potentialIndex + 1, true);
  lightbox.pswp.prev = () => customGoTo(lightbox.pswp.potentialIndex - 1, true);
});

I haven't tested the above but you get the idea

@acwolff
Copy link

acwolff commented Oct 6, 2021

@bndelrio I tried your Option 2 and I think it works!

Compare my album with transitions with the same album without Option 2.
You see now too transitions in the slide show!

The transition is rather fast, how can I make it longer?

@dimsemenov why is this a hidden feature?

@NickBodliev
Copy link

@acwolff I am not sure if you still need this, but I am sharing this anyway as it might be useful to others

The following snippet alters the transition duration (addition to the solution offered by @rbndelrio):

#pswp__items {
  transition-duration: .6s;
}

@acwolff
Copy link

acwolff commented May 31, 2023

@NickBodliev I am very interested, but where should I put your code?
I tried this:

import PhotoSwipeLightbox from './photoswipe-lightbox.esm.min.js'; 
  const options = { 
    transitionDuration: 600,

but this does not work.

@NickBodliev
Copy link

@acwolff the snippet I mentioned should be placed in the styles file of the component which uses photoswipe

@acwolff
Copy link

acwolff commented Jun 1, 2023

@NickBodliev I tried that already earlier, but that does not work either:

I added

<style>
#pswp__items {
  transition-duration: 1.6s;
}
</style>

To my main page https://andrewolff.jalbum.net/PhotoSwipeWeb-with-transitions/

The code of @rbndelrio is in page https://andrewolff.jalbum.net/PhotoSwipeWeb-with-transitions/res/initGallery.js

@NickBodliev
Copy link

Have you implemented the customToGo method? Are you using that method? The css would work without that
@acwolff

@acwolff
Copy link

acwolff commented Jun 1, 2023

Yes, in page https://andrewolff.jalbum.net/PhotoSwipeWeb-with-transitions/res/initGallery.js :

import PhotoSwipeLightbox from './photoswipe-lightbox.esm.min.js'; 
	const options = { 
	  gallerySelector: '#gallery', 
	  childSelector: 'a', 
	  counter: false, 
	  showHideAnimationType: 'zoom',
	  showAnimationDuration: transtime,
	  hideAnimationDuration: transtime,
	  bgOpacity:  1.0,
	  paddingTop: 0,
	  paddingBottom: 0,
	  wheelToZoom: true,
	  loop:  false,
	  imageClickAction: (releasePoint, e) => {  playpause() },  
	  tapAction: (releasePoint, e) => { if (isImage) playpause() },  
	  closeTitle: 'Sluit',
	  zoomTitle:  'Zoom in/uit (gebruik muis wiel op een PC)',
	  arrowPrevTitle: 'Vorige dia (pijl naar links toets)',
	  arrowNextTitle:  'Volgende dia (pijl naar rechts toets)',
	  mouseMovePan: true,
	  initialZoomLevel: 'fit',
	  secondaryZoomLevel: 'fill',
	  maxZoomLevel: 1,
	  mainClass:  'pswp--buttons-visible',	
 	  pswpModule: () => import('./photoswipe.esm.min.js')
 	}; 
	const lightbox = new PhotoSwipeLightbox(options);
	const customGoTo = (index, animate = false) => {
 	  const ctx = lightbox.pswp;
 	  index = ctx.getLoopedIndex(index);
	  const indexChanged = ctx.mainScroll.moveIndexBy(index - ctx.potentialIndex, animate);
	  if (indexChanged) {
		ctx.dispatch('afterGoto');
 	  }
	}
    lightbox.on('uiRegister', function() {
        lightbox.pswp.next = () => customGoTo(lightbox.pswp.potentialIndex + 1, true);
        lightbox.pswp.prev = () => customGoTo(lightbox.pswp.potentialIndex - 1, true);
        lightbox.pswp.ui.registerElement({
          name: 'custom-caption',
          order: 1,
          isButton: false,
          appendTo: 'root',
          html: 'Caption text',
          onInit: (el, pswp) => {
            lightbox.pswp.on('change', () => {
              const currSlideElement = lightbox.pswp.currSlide.data.element;
              let captionHTML = '';
              if (currSlideElement) {
                  captionHTML = currSlideElement.dataset.caption;
              } else  captionHTML = strCap[slide_index];
              if (captionHTML.length>0 && !isPansph) { 
                  el.style.display = "block";                 	
                  el.innerHTML = captionHTML;
                  if (captionHTML.indexOf("<audio") > -1) initTooltips();
              }
              else {
                 el.style.display = "none";
              }
            });
          }
        });

@NickBodliev
Copy link

@acwolff do you have the animation so far?

@acwolff
Copy link

acwolff commented Jun 1, 2023

I am not sure, look for your self to my implementation:

https://andrewolff.jalbum.net/PhotoSwipeWeb-with-transitions/

@NickBodliev
Copy link

@acwolff the animation looks great
It looks like you have already specified the transition duration and the animation works as expected

Screenshot 2023-06-01 at 11 47 52 AM
Screenshot 2023-06-01 at 11 48 45 AM

@acwolff
Copy link

acwolff commented Jun 1, 2023

@NickBodliev I am looking to the tansitions after I opened the ligthbox and go to the next slide. I don't see there a transition of 1.6 sec.

BTW I added the 1.6s style rule, but see in the F12 log 800ms:
F12

photoswipe.css contains this:

/* defined via js:
  --pswp-transition-duration: 333ms; */

So apparently somewhere else this 800ms is defined.

@NickBodliev
Copy link

the 800ms trnasition duration is defined by Photoswipe (via JS). This is the duration of the open/close animation
You can change that with showAnimationDuration and hideAnimationDuration properties – the default value is 333ms (see more here)
@acwolff

@acwolff
Copy link

acwolff commented Jun 1, 2023

oh i'm a stupid klutz, i already used that parmeter! I have now set it to 1500ms, but that only affects the transition when opening and closing the lightbox, not the transition from slide to slide in the lightbox.

But showAnimationDuration and hideAnimationDuration do have the same values:

import PhotoSwipeLightbox from './photoswipe-lightbox.esm.min.js'; 
	const options = { 
	  gallerySelector: '#gallery', 
	  childSelector: 'a', 
	  counter: false, 
	  showHideAnimationType: 'zoom',
	  showAnimationDuration: 1500,
	  hideAnimationDuration: 1500,	

and still there is no 1500 ms transition from slide to slide in the lightbox.

@NickBodliev
Copy link

showAnimationDuration and hideAnimationDuration are responsible for opening/closing of the photoswipe only
the css I provided above is going to alter the animation duration between slides
@acwolff

@acwolff
Copy link

acwolff commented Jun 1, 2023

@NickBodliev I have added your code

#pswp__items {
  transition-duration: 1.6s;
}

to my css file res\common.css, and now it works as you can see in my test album:.

I have no idea why it did not work before!

Anyhow thanks for your help and patience!

Edit:

Cheered too early. it worked once, but not anymore
Can you show me a working album?

In Firefox I see that the 1.6s from my css file is overruled:

FireFox

But the even the remaining 1500ms does not apply to the slide to slide transition.

@acwolff
Copy link

acwolff commented Jun 1, 2023

I tried:

#pswp__items {
  transition-duration: 1.6s !important;
}

But that does not help.

@arnowelzel
Copy link

JFTR: The proposal as suggested in #1765 (comment) seems to work with a current version now even with looping.

@acwolff
Copy link

acwolff commented Nov 26, 2023

@arnowelzel where / how did you define the transition-duration?

@acwolff
Copy link

acwolff commented Nov 26, 2023

@arnowelzel thanks for the demo's.

I like to change the transition time, because you hardly see a transition effect with the default tgransition time of 800 ms,
but I have no idea how to do that with the standard minified Photoswipe library.

@arnowelzel
Copy link

@acwolff yes, the transition is quite fast - but personally I find it just right. You still can see that there is a transition, but you dont't feel like you have to wait for ages when swiping through a larger image collection (not all users may be aware that the keyboard shortcuts for left/right work even during the transition and they don't have to wait for it to complete before changing to the next image).

And for comparison: PhotoSwipe 4 was more or less the same - https://wordpress-demo.arnowelzel.de/lightbox-with-photoswipe/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants