Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS How do i stop Jquery animation “+=” when this is limited

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #44519
    Anonymous
    Inactive

    i’m working on this slider that slides div to the left or right. I want it to stop when there is no other div to go to next. How do i achieve that? Here is what i have for example http://codepen.io/Jarolin/pen/mlzJh

    #133991
    Anonymous
    Inactive

    Nothing?

    #134011
    Mottie
    Member

    @Jarolin What makes it difficult to give you an answer is that slides are traditionally within a container and that container is positioned instead of the slides themselves, if you want to float the slides.

    What the demo above does is position each slide separately. And also, because the slides aren’t wrapped, you can’t for example have 10 slides in a row, because extra slides would either wrap to the next line or make the document extend beyond the browser window (scroll bar to the right).

    More traditional markup with overflow hidden would allow for that, [something like this](http://codepen.io/Mottie/pen/aunjE):

    #134018
    CrocoDillon
    Participant

    > What makes it difficult to give you an answer is that slides are traditionally within a container and that container is positioned instead of the slides themselves

    This.

    I would however keep track of the current index and for example go to left only `if (index > 0)` and go to right only `if (index < $('.field').length - 1)` or something (length from a var, this is just an example). You can then slide to that field using the same jQuery as I used here: http://codepen.io/CrocoDillon/pen/lozFt


    @Mottie
    , your implementation comparing the position fails if you click the next button repeatedly, that’s why I like comparing to something that doesn’t change during the animation.

    #134021
    Anonymous
    Inactive

    @CrocoDillon @Mottie These both work great. but i would want the user to navigate back and forth, Not just one way.

    #134023
    CrocoDillon
    Participant

    I guess you’re referring to my Pen, only linked that for the animate part ;p It was easier than creating a new Pen. The only difference with going back is you decrement the index instead of increment.

    #134024
    Anonymous
    Inactive

    @CrocoDillon Huh?. Sorry i’m kind of a Jquery noob and am not really sure what you meant by that.

    #134025
    Mottie
    Member

    Yeah, @CrocoDillon was right, I should have just used an index ;)

    I’ve updated [my demo](http://codepen.io/Mottie/pen/aunjE).

    #134055
    Anonymous
    Inactive

    @Mottie Will i be able to add new panels and it will slide them normally too?

    #134077
    Mottie
    Member

    @Jarolin: with the update I just made, yes… it now resizes the `#insidewrapper` to fit all of the slides inside.

    #134083
    Anonymous
    Inactive

    @Mottie Thank’s for all your help. I applied the Jquery and it’s working great. http://reallycoolstuff.net/PROJECTS/Unica/index.html Although there is one problem. When i zoom out and navigate through the slides it delocates. and things get alittle weird. Is there a solution to this problem?

    #134107
    Anonymous
    Inactive

    Is there a way of fixing that or no?

    #134108
    Mottie
    Member

    It looks like the width of the slides are 1285px but the container is set to 95%… that’s why there is an inconsistency.

    Now you see why it’s easier to use a plugin instead of writing your own.

    To fix it you’ll need to get the window size and change the width of all of the slides, then bind to the window resize event, but make sure it is throttled, to re-adjust the slide sizes.

    #134109
    Anonymous
    Inactive

    @Mottie haven’t found an ideal plug-in for what i’m trying to do.

    #134124
    CrocoDillon
    Participant

    It appears to be a bug with jQuery animate only in Chrome: http://bugs.jquery.com/ticket/5565 … you can try to use jQuery just to set the `left` (and don’t use something like `left += width`, but keep a var keeping the current left value yourself) and use CSS transitions to handle the animation.

Viewing 15 posts - 1 through 15 (of 19 total)
  • The forum ‘CSS’ is closed to new topics and replies.