malsup / cycle2

2nd gen cycling
899 stars 236 forks source link

Is there anyway to do the scrolling animation in reverse? #458

Open oktalk opened 10 years ago

oktalk commented 10 years ago

I'm using the carousel plugin with the pager. Is it possible to reverse the scrolling effect of when a user clicks on a pager item, to move to a slide that comes before the current slide, so that the carousel animates from the right to the left?

malsup commented 10 years ago

Doesn't the demo page show examples of that?

http://jquery.malsup.com/cycle2/demo/carousel.php

oktalk commented 10 years ago

No. In the demo page when you click on a pager item that comes before the current slide the carousel animates from left to right. I'm trying to reverse that animation.

I specifically only need to revers any previous scrolling effects. I.E.: if a user clicks on a pager item to advance the carousel, the carousel scrolls from the right to the left like normal. If a user clicks on a pager item to move to a previous slide, the carousel would again scroll from the right to the left instead of scrolling from the left to the right.

I tried to use something like "fx: 'scrollHorz',rev: true" but that doesn't seem to work. Here is a fiddle of my unsuccessful attempt: http://jsfiddle.net/F2cdH/

Laubeee commented 10 years ago

I think I have the same question. I'd like to use ScrollHorz but with animation reversed. reverse=true will also reverse the order, which I dont want.

Laubeee commented 10 years ago

@oktalk This is my quick fix ;)

i copied the scrollHorz function and added fwd = !fwd;

$.fn.cycle.transitions.scrollHorzRev = { before: function( opts, curr, next, fwd ) { fwd = !fwd; opts.API.stackSlides( curr, next, fwd ); var w = opts.container.css('overflow','hidden').width(); opts.cssBefore = { left: fwd ? w : - w, top: 0, opacity: 1, visibility: 'visible', display: 'block' }; opts.cssAfter = { zIndex: opts._maxZ - 2, left: 0 }; opts.animIn = { left: 0 }; opts.animOut = { left: fwd ? -w : w }; } }