Skip to content

Unpredictable slider.targetPage & slider.currentPage #233

Closed

Description

@samf3

I've read the docs, but there's still no sense in the results I'm seeing.

In onSlideBegin() it looks as if currentPage is 1-based and targetPage is 0-based. I am not using the cloned panel feature.

If I am on slide # 3 (= index 2), say, and I click to go back, then I expect currentPage=2 and targetPage=1. But I get currentPage=3 and targetPage=1. Similarly for other use cases.

Surely I'm doing something wrong?

Activity

  1. Mottie commented on Dec 16, 2011

    @Mottie
    Contributor

    Hi samf3!

    the currentPage will include the cloned pages and doesn't get updated until the onSlideComplete() function. The targetPage will be the page where the slider will end up, it is updated for the onSlideBegin() function. If you are not seeing this behavior, then maybe there is a problem.

  2. samf3 commented on Dec 16, 2011

    @samf3
    Author

    Hi Mottie, and thanks for a truly awesome plugin.

    I am using infiniteSlides:false, so I "should not" have any cloned pages. Also I am using "external" controls, but I assume that whould not make a difference as the slider scrolls as expected, it's only that those properties are inconsistent.

    The detail in your answer is exactly what I am expecting as normal behavior, but I get what I described above. I am assuming I am doing something wrong because this plugin is at a mature state. Are there any other gotchas I should know of in that event?

    Are they both 0-based or 1-based?

  3. samf3 commented on Dec 16, 2011

    @samf3
    Author

    You said that currentPage includes the count of the cloned pages. If infiniteSlides is off, then I assume that currentPage takes that into account? If it doesn't, then that would explain the above results (unless I'm doing something wrong-more probable! :) ).

  4. Mottie commented on Dec 16, 2011

    @Mottie
    Contributor

    Nope, you're right, it is a bug... demo

    I'll patch it up :)

  5. samf3 commented on Dec 16, 2011

    @samf3
    Author

    Wow I thought I was going mad :) Thanks.

  6. Mottie commented on Dec 17, 2011

    @Mottie
    Contributor

    Ok, this has been fixed in version 1.7.20. Thanks for reporting it!

  7. samf3 commented on Dec 17, 2011

    @samf3
    Author

    Okay works better now, but there may still be an issue.

    When the plugin first loads, I trap the onInitialized() event, and I observe that currentPage==1. Should it not be 0?

    Take a look at that demo you made, click away from the zeroth slide, then come back to it, and you'll see that currentPage==1. That seems to be because it starts off at 1 rather than 0.

  8. Mottie commented on Dec 17, 2011

    @Mottie
    Contributor

    It's working for me... make sure you refresh your browser cache.

    Edit: Oh I see what you are saying... but the currentPage is a 1-based index of the panels, not zero based. So it should never be zero.
    Actually, from your initial question, both currentPage and targetPage are 1-based. The only way to determine if the slider is going to show a cloned page is by looking at exactPage (undocumented)

    Edit 2: Ugh, ok exactPage is off now LOL... here's an updated demo - it shouldn't be a big deal, but it might effect the FX extension.

  9. samf3 commented on Dec 17, 2011

    @samf3
    Author

    I'm not fully understanding this. Please bear with me!
    I will assume both are 1-based as you said, and that there are no cloned panels.

    So, using your newest demo as a reference:

    • in onInitialized(), you're on slide 1, so currentPage==1 and targetPage==undefined --good
    • click on slide 2
      in onSlideInit()/onSlideBegin() you'd expect currentPage==1 and targetPage==2, BUT currentPage==1 and targetPage==1
      then in onSlideComplete() you'd expect currentPage==2 and targetPage==2, BUT currentPage==2 and targetPage==1
    • click on slide 1 to go back to the beginning
      in onSlideInit()/onSlideBegin() you'd expect currentPage==2 and targetPage==1, BUT currentPage==2 and targetPage==0
      then in onSlideComplete() you'd expect currentPage==1 and targetPage==1, BUT currentPage==1 and targetPage==0

    It seems as if currentPage is 1-based, and targetPage is 0-based.

    PS: be careful when you inspect that demo in jsfiddle, every time I move away from that tab (I'm in Firefox BTW), it automatically runs the script for some reason, and gives more results, which initially threw me off.

    PS: another thing that is worrying me, is that infiniteSlides is off, and yet the slider nonetheless wraps. The green coloring makes it hard to see, so check it in Firebug and you'll see the activePage class gets added to the first/last li. I feel that these problems are probably related somehow.

    Sorry I wish I could help dig into the codebase and help, but its big and I don't know where to start! :(

  10. Mottie commented on Dec 17, 2011

    @Mottie
    Contributor

    Are you really really sure you cleared your browser cache? Click on the "Manage Resources" header, then click on "jquery.anythingslider.js" and see what version you see. If it isn't 1.7.20, then hold down your Shift key and click on the browser reload button. Then run the demo. Because this is a screen shot of what I'm seeing after following the same steps you describe above (demo used).

    event variables

    As for the second problem, the demo has infiniteSlides set to false (not off) and from viewing the slider in Firebug, I see the activePage class applied appropriately. I even set the infiniteSlides option back to true and it's fine.

  11. samf3 commented on Dec 17, 2011

    @samf3
    Author

    WOW, that was weird. You're right it was the browser. I obviously cleared the cache but it didn't work, and I didn't realise it was using the old version. After struggling for a while, I loaded the script into a new tab, cleared the cache, reloaded the script, which showed 1.7.20. Then when I reloaded jsfiddle, it picked up the new version. Weird!

    As for the wrapping, yes, in my code I used stopAtEnd: true so I was surprise by the demo's results. All's well now.

    Thanks for fixing this!

  12. samf3 commented on Dec 29, 2011

    @samf3
    Author

    Sorry to bring this up again, but I want to verify there isn't a regression bug in the latest version. This time I cleared the cache and verified the version of the plugin! :)

    I modified your demo, check here: http://jsfiddle.net/36MDS/10/

    This time I'm not checking the slider.targetPage index, but rather the index of the slider.$targetPage object, and it appears to be incorrect. Please have a look at the demo and see if you get the same results?

  13. Mottie commented on Dec 29, 2011

    @Mottie
    Contributor

    DOH, ok fixed again. Thanks for finding it.

  14. samf3 commented on Dec 30, 2011

    @samf3
    Author

    works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions