Jump to content
Search Community

help carousel

Daniel Ruiz test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi Daniel and welcome to the GreenSock forums.

 

It's a bit hard to get a good idea of what you're after with what you wrote and the picture you added in the post.

 

Please take a look at this post in order to learn how to create a reduced live sample in Codepen, which makes support incredibly easier and faster:

 

http://forums.greensock.com/topic/9002-read-this-first-how-to-create-a-codepen-demo/

 

Rodrigo.

  • Like 1
Link to comment
Share on other sites

Thank you very much, Rodrigo, not if you're Latino, but thank you very much for your help, follow the tutorials, and you started your example was helpful, but I need the elements of the container out one after the other with a specific margin.

 

See the Pen IjnBv by ndanielruiz (@ndanielruiz) on CodePen

 

thank you very much.

 

Gracias soy de Colombia.

Link to comment
Share on other sites

Hey Daniel,

 

Basically the margin between slides is given by their widths, what you can try is give the slides a 94% width in the css and a 3% margin left in order to create a separation between them. Check the following example that was made based on Chrysto's codepen:

 

See the Pen CeDkc?editors=011 by rhernando (@rhernando) on CodePen

 

Also in order to create a random logic for a determinated number of elements you need to round the numbers, like this:

var totalSlides = $(".slide").length; // for example 8 in your case

// returns a number between 0 and 7, which matches the index position of the slides
console.log( Math.floor( Math.random() * totalSlides ) ); 

All you have to add is a conditional logic to avoid selecting the same number twice in a row, because that'll mean that the current visible slide will be the next one to be animated. You can store it in a variable and check the number with that one, if it's the same run the random number logic again, like that you'll get a new slide each time the code is executed, something like this:

var totalSlides = 8,
    currentSlide = 0,
    randomSlide;

function getRandomSlide()
{
  randomSlide = Math.floor( Math.random() * totalSlides );
  if(randomSlide === currentSlide)
    {
      getRandomSlide();
    }
  else
    {
      console.log( randomSlide );
      
      currentSlide = randomSlide;
    }
}

getRandomSlide();

Rodrigo.

  • Like 1
Link to comment
Share on other sites

Hello

 

To add to Rodrigos awesome advice..

 

Here is a GSAP Image Slider i made that cycles infinity..

 

See the Pen qxsfc by jonathan (@jonathan) on CodePen

 

It does this by using append() .. and when a slide is shown and then faded out it moves the element to the bottom .. look at

See the Pen qxsfc by jonathan (@jonathan) on CodePen

and look in the HTML inspector to see the behavior i describe.

 

It is just a basic image slider, but it might give you some ideas..

 

This also might be of help.. this is an example of Infinite Scroll by GreenSocks Mighty Carl .. it was done in Flash, But the overall concept is still the same for HTML5. Basically after hiding the last image that hides it self, you remove the element once hidden, and append it to the end of your element list. And just repeat that process after each animation step.

 

Easy Infinite Scroll - Part 1

Easy Infinite Scroll Part 2

 

Hope this helps?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...