Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to get the scroll position for the slidee #75

Closed
ghost opened this issue Jul 20, 2013 · 9 comments
Closed

Is there a way to get the scroll position for the slidee #75

ghost opened this issue Jul 20, 2013 · 9 comments

Comments

@ghost
Copy link

ghost commented Jul 20, 2013

I want to get the number of pixels the scroll bar has been scrolled.

For example, initially the CSS of the slidee shows this:

style="transform: translateZ(0px) translateY(0px)"

Now, when I scroll a little, it changes to:

style="transform: translateZ(0px) translateY(-113px)"

The -113 is the value I want to be able to get programmatically.

How can I do this?

@darsain
Copy link
Owner

darsain commented Jul 20, 2013

@darsain darsain closed this as completed Jul 20, 2013
@ghost
Copy link
Author

ghost commented Jul 20, 2013

It does NOT work.

The sly.pos object returns just the same values for all the properties after the scroll.

No property returns any changes (or anything similar to -113 in my case)
I am using the latest build of Sly

@ghost
Copy link
Author

ghost commented Jul 20, 2013

There is one way:

You first get this:

$(sly.slidee).css('transform')

which returns a matrix, which you then need to parse to get the desired value.

matrix(1, 0, 0, 1, 0, -113)

But I was looking for something straightforward, and I think Sly should expose it.

@darsain
Copy link
Owner

darsain commented Jul 20, 2013

If what you say would be true, Sly wouldn't work, because the output of translateX/Y directly consumes sly.pos.cur value. This is more or else what's happening:

slidee.style.transform = 'translateX(' + (-sly.pos.cur) + 'px)';

sly.pos.cur is always a direct representation of current SLIDEE position, which - with the combination of other properties in sly.pos object - is exactly what you are asking for.

sly variable obviously being an initiated Sly instance:

var sly = new Sly(frame, options).init();

If you don't see the current position property change, it means you are retrieving it before the scrolling happened.

Also, properties like start & end change only when you change the content size, and reload the sly instance. They are the indicators of boundaries - meaning what is the min & max value of properties cur & dest.


Basically I've just rewritten the documentation I've referred you to. Glad that it is all documented so this wouldn't have to happen... :)

@ghost
Copy link
Author

ghost commented Jul 20, 2013

I am ONLY scrolling -- and NOT reloading the instance neither am I changing the content size.

Could this be because of this?
If yes, what is the way to retrieve the value?

UPDATE: It does NOT work even after calling the reload:

sly.reload()

Also note that I am getting the pos object in a click handler so I am in no way retrieving it before the scrolling happened.

Can you please point out where I am doing something wrong?

UPDATE 2: MY BAD

You were right. I was doing something wrong.

When I display the whole object sly.pos it showed the unmodified value. But if I access sly.pos.cur, it always shows the updated value.

Anyway thanks for helping me.

UPDATE 3:

The pos object and pos.cur property show the SAME value in Chrome, but not in Firefox (19).
(Try manually dragging the scrollbar a little, and then check; the pos object will show a different value for cur property and pos.cur (fetched directly) will show a different value)

@darsain
Copy link
Owner

darsain commented Jul 20, 2013

  1. No.
  2. You retrieve it from the position object, whenever you need it. How to get to the sly properties (one of which is the position object) is documented on the same page.
  3. No.

Overall, just RTFM dude.

@ghost
Copy link
Author

ghost commented Jul 20, 2013

Ok, just try this jsFiddle in Firefox (version 19):

By clicking on the content you will see the scroll bar value displayed in the console.

First scroll down (drag the bar) a little and click:
you will see both pos object and pos.cur showing you he same values

Then, scroll up (drag the bar don't use wheel) and click:
At this point pos object shows the old value for the cur property, but fetching pos.cur shows the updated value.

The jsFiddle is:
http://jsfiddle.net/QrLFC/

(It works perfectly in Safari and Chrome)
And your documentation is extremely helpful and elaborate -- AND I have read it all at least 3 times :-) Because I am using Sly for something complex.

@darsain
Copy link
Owner

darsain commented Jul 20, 2013

Fetching pos.cur can't change it's value. It's not a getter, it's a static property.

Tried the fiddle, works as expected.

@ghost
Copy link
Author

ghost commented Jul 20, 2013

Did you try it in Firefox 19 -- because on my end, in FF 19 it's not working. Maybe I am doing something wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant