flickity icon indicating copy to clipboard operation
flickity copied to clipboard

Continuous autoPlay scrolling - autoScroll

Open slcr opened this issue 9 years ago • 51 comments

Looks awesome and quite perfect to me. The only thing i’m missing so far is some kind of ‘autoScroll’ when using the ‘freeScroll’ Option. ‘autoPlay’ is not working as expected.

( copy of comment made here: https://css-tricks.com/creating-responsive-touch-friendly-carousels-with-flickity/#comment-1592976 )

slcr avatar Mar 06 '15 09:03 slcr

Thanks for this feature request.

Add a 👍 reaction or subscribe to this issue if you would like to see this feature added. +1 comments will be deleted.

desandro avatar Mar 06 '15 13:03 desandro

+1 for a continous, ticker-style scroll

eballeste avatar Apr 10 '15 16:04 eballeste

+1 for continuous autoplay scrolling

As a separate feature perhaps? Something like continuousAutoPlay: true or autoPlaySkipCell: true. You can still swipe/navigate to cells this way.

mauricesnip avatar May 26 '15 07:05 mauricesnip

+1

EugeneDae avatar Jul 26 '15 20:07 EugeneDae

+1

adam-h avatar Aug 10 '15 20:08 adam-h

I just implemented this as I needed it for my project, would be great to have it upstream and may be useful to others :)

adam-h avatar Aug 14 '15 22:08 adam-h

@adam-h thanks for this!

However I ran into a bug where the slider would skip a bit on mouseleave.

I tried fixing it inside your release but the code was a bit hard to get. Anyway, I've pinned down the root of the problem and it is the minimun return value of 10 inside proto.animate:

proto.animate = function() {
  if( this.isContinuous ) {
    var passed = +new Date() - this.lastAnimate;
    var move = Math.min( ( 1 / passed ) * Math.abs( this.freePlaySpeed ), 10 );

i fixed it as so:

proto.animate = function() {
  if( this.isContinuous ) {
    var passed = +new Date() - this.lastAnimate;
    var move = ( 1 / passed ) * Math.abs( this.freePlaySpeed );
    move = (isFinite(move)) ? move : 0;

But i'm not sure what the 10 was for originally so don't want to PR.

PatrikLythell avatar Sep 08 '15 09:09 PatrikLythell

@PatrikLythell The Math.min() was to stop it moving too much in one step (if the animation frame were delayed a significant amount it would jump along a little).

The finite check looks good. What are your thoughts on removing the Math.min() as it could be moved to after the isFinite() check or just removed.

adam-h avatar Sep 08 '15 19:09 adam-h

+1 for a constant speed scrolling autoplay

maxackerman avatar Dec 05 '15 22:12 maxackerman

+1 that would be really useful

wagich avatar Dec 17 '15 17:12 wagich

I'm going to stick with my position and decline this feature request. The autoPlay feature is a suitable solution. Adding another type of auto-motion behavior is not worth the cost of additional complexity.

Thanks for all your feedback!

desandro avatar Feb 07 '16 18:02 desandro

Anyone found an alternative to Flickity which has this feature, please?

daslicht avatar May 16 '16 14:05 daslicht

@daslicht I found what you're looking for and it even has support all the way back to IE5:

<marquee></marquee>

In all seriousness, I have had clients ask for continues scroll rather than pausing. Maybe @desandro will get to it by V3.

stefenphelps avatar Jul 22 '16 14:07 stefenphelps

@stefenphelps

<marquee></marquee>

don't give you an infinite flow, at least I haven't found a solution , yet.

The text (or something else) would run entirely from one side to another until it disappear completely. After that it would restart.

Try to make something like this with the marquee tag and post the result please:

http://www.davidpayr.com

daslicht avatar Jul 22 '16 16:07 daslicht

Would love to see this feature

HowdyMcGee avatar Dec 28 '16 16:12 HowdyMcGee

@desandro hopefully it's OK to post this here...

I stumbled across this site which seems to be using Flickity combined with what I assume is some custom code to achieve the continuous marquee effect. I haven't spent much time looking to reverse engineer but I thought it might be useful to post incase someone else wants to take a look.

Checkout the Instagram section here:

https://www.mendo.nl/about/flagship-store/

pstinnett avatar Mar 30 '17 18:03 pstinnett

Hey guys,

I took a look into source code of flickity and found pretty simple solution. It's not thoroughly tested etc, just a quick idea and example. Implementing this in current project, will see how it behaves.

    var previousDate; // if undefined, animation is paused

    function step() {
        if (typeof previousDate == 'undefined') { return; }

        var date = new Date();
        var diff = (date - previousDate) / 20; // in this case 20 is "speed constant", the higher value, the slower movement
        previousDate = date;

        /* key 2 lines of code */
        flkty.x -= diff;
        flkty.positionSlider();

        requestAnimationFrame(step);
    }

    function play() {
        if (typeof previousDate == 'undefined') {
            previousDate = new Date();
        }

        requestAnimationFrame(step);
    }

    function pause() {
        previousDate = undefined;
    }

    play();

Initially I planned to call play/pause on dragStart / dragEnd events, but somehow flickity works nice without it. But it might be worth considering if something went wrong.

r00dY avatar Aug 22 '17 11:08 r00dY

@r00dY Thank you for this! It works quite nice, but on iOS scrolling the page will cause the current slider position to reset.

bennyjien avatar Aug 29 '17 03:08 bennyjien

@r00dY @bennyjien Would you please share any more info on how you've implemented your code? Currently toying around with Flickity and wondering if there is indeed a chance of turning it into a continuous scrolling slideshow. Thanks in advance

antoniofelizardo avatar Sep 27 '17 15:09 antoniofelizardo

To bad this won't be implemented. I think Flickity is probably the best slider out there, but I realy need this for a webapp. It seems a logical feature request and autoPlay does not offer a solution as it is now. Other sliders (such as Slick) offer a combination of settings with which you can achieve every effect:

speed: 2500,
autoplay: true,
autoplaySpeed: 0,

Unfortunately, the responsiveness of Flickity is far better than most.

TomDeSmet avatar Feb 05 '18 15:02 TomDeSmet

I needed this behaviour for my site too and i found @pstinnett example on that mendo.com website. I looked a bit in the source code and it is failry easily done in fact... here's the mimimum required code to do it (without pause on hover etc... you need to implement that yourself or if I ever get to it i will post it here.):

init() {
    this.flkty = new Flickity('<someDOMElement>', {
          prevNextButtons: false, 
          pageDots: false,
          wrapAround: true,
          freeScroll: true
     });
    this.flkty.x = 0;
    this.loop();
}

loop() {
    this.flkty.x--;
    this.flkty.integratePhysics();
    this.flkty.settle( this.flkty.x);
    window.requestAnimationFrame(this.loop.bind(this));
}

koraysels avatar Apr 16 '18 16:04 koraysels

@koraysels Did you already implemented it? I can't get it working.

pveen2 avatar Jun 29 '18 15:06 pveen2

@r00dY @bennyjien I'm also try to get something like this working but unsure how to implement this code suggestion. It's not playing ball for me.

richardwiggins avatar Aug 13 '18 13:08 richardwiggins

Following @koraysels pattern, I believe I found a really nice way to apply pause/play into his solution:

// For every container, do the following:
_$container.each((i, el) => {
	// Set a unique animation request id variable
	let requestId;

	// Check if the slider contains more than 3 slides
	if($(el).children().length > 3) {
		// Initialize the slider
		const mainTicker = new Flickity('.js-main-slider', {
			accessibility: true,
			resize: true,
			wrapAround: true,
			prevNextButtons: false,
			pageDots: false,
			percentPosition: true,
			setGallerySize: true,
		});

		// Set initial position to be 0
		mainTicker.x = 0;

		// Start the marquee animation
		play();

		// Main function that 'plays' the marquee.
		function play() {
			// Set the decrement of position x
			mainTicker.x = mainTicker.x - 1.5;

			// Settle position into the slider
			mainTicker.settle(mainTicker.x);

			// Set the requestId to the local variable
			requestId = window.requestAnimationFrame(play);
		}

		// Main function to cancel the animation.
		function pause() {
			if(requestId) {
				// Cancel the animation
				window.cancelAnimationFrame(requestId)

				// Reset the requestId for the next animation.
				requestId = undefined;
			}
		}

		// Pause on hover/focus
		$(el).on('mouseenter focusin', e => {
			pause();
		})

		// Unpause on mouse out / defocus
		$(el).on('mouseleave', e => {
			play();
		})
	}
})

roberrrt-s avatar Aug 27 '18 11:08 roberrrt-s

@roberrrt-s nice solution dude! Thanks for sharing 👍

jshrssll avatar Nov 30 '18 10:11 jshrssll

Is there still no option for continuous autoPlay scrolling after clicking on the slide?

theleeno84 avatar Jan 10 '19 09:01 theleeno84

If anyone needs @roberrrt-s solution in Vanilla JS, I've re-worked it slighlty. Thanks for doing the hard work though :) Might not be perfect, but working for us at least.

const carousels = document.querySelectorAll('.carousel'), 
  args = {
    accessibility: true,
    resize: true,
    wrapAround: true,
    prevNextButtons: false,
    pageDots: false,
    percentPosition: true,
    setGallerySize: true,
  };

carousels.forEach((carousel) => {
  let requestId;

  if (carousel.childNodes.length > 3) {
    const mainTicker = new Flickity(carousel, args);

    // Set initial position to be 0
    mainTicker.x = 0;

    // Start the marquee animation
    play();

    // Main function that 'plays' the marquee.
    function play() {
      mainTicker.x = mainTicker.x - 1.5;
      mainTicker.settle(mainTicker.x);
      requestId = window.requestAnimationFrame(play);
    }

    // Main function to cancel the animation.
    function pause() {
      if (requestId) {
        window.cancelAnimationFrame(requestId)
        requestId = undefined;
      }
    }

    // Pause on mouse over / focusin
    carousel.addEventListener('mouseover', pause, false);
    carousel.addEventListener('focusin', pause, false);

    // Unpause on mouse out / focusout
    carousel.addEventListener('mouseout', play, false);
    carousel.addEventListener('focusout', play, false);

  }

});

discoliam avatar May 15 '19 19:05 discoliam

Do any of these solutions do "pause on hover" on the continuously scrolling carousel?

srikat avatar May 25 '19 00:05 srikat

@srikat Mine and @discoliam does.

roberrrt-s avatar Jun 07 '19 08:06 roberrrt-s

@srikat Mine and @discoliam does.

Is the pause instant or after some delay?

srikat avatar Jun 07 '19 08:06 srikat