Hot to get the current scroll position?

5,463 views
Skip to first unread message

Darko Romanov

unread,
Jun 16, 2012, 3:59:55 AM6/16/12
to isc...@googlegroups.com
Hi all,

I have to make a sort of "lightbox popup" to show big images in a mobile app that uses iScroll. I thought to do something like:

- I append the big image to the dom with absolute position
- I read the current scroll position
- I set the css top "property" of the big image to make it centered in the page

I've seen that the scroller element is moved with the -webkit-transform proprerty (at least in Chrome), is there an API to get the value of the current scrolling position? Have I to read the css property?

Thanks

Kevin Siml

unread,
Jun 29, 2012, 4:55:11 PM6/29/12
to isc...@googlegroups.com
I had a similar problem and have solved it

in iscroll.js search

scrollTo: function (x, y, time, relative) {

var that = this,

step = x,

i, l;


that.stop();


if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }];

for (i=0, l=step.length; i<l; i++) {

if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }

that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });

}


that._startAni();

},


after that write


 getScrollY: function () {

 var that = this;

 return that.y;

 },  

 

 getScrollX: function () {

 var that = this;

 return that.x;

 },  


the position in your project you can read so:


myScroll.getScrollY()

myScroll.getScrollX()


Greets Kevin

sorry for the bad english

http://www.preis-finder.info

Luis Montemayor

unread,
Jun 29, 2012, 6:52:28 PM6/29/12
to isc...@googlegroups.com
Thanks Kevin!

And in order to know in which "page" I am, what I am doing is to divide getScrollX to the size of the "snaped" element.

Keir Moff

unread,
Aug 8, 2013, 5:17:02 AM8/8/13
to isc...@googlegroups.com
Is it worth creating a pull request for this addition, or is it/will it be part of IScroll 5 core already?

Keir Moff

unread,
Aug 8, 2013, 5:36:29 AM8/8/13
to isc...@googlegroups.com
Realised you can just poll for the coordinates with myScroll.x or myScroll.y - bind it to on scrollStart/scrollEnd or anything really.

Matteo Spinelli

unread,
Aug 9, 2013, 8:16:04 AM8/9/13
to isc...@googlegroups.com
myScroll.x and myScroll.y always store the current position. if you need to read those values when the scroller is moving refer to the probe demo.

Matt

Keir Moffatt

unread,
Aug 11, 2013, 6:21:14 AM8/11/13
to isc...@googlegroups.com
Thanks!


--
You received this message because you are subscribed to the Google Groups "iScroll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iscroll+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
iamkeir.com / @iamkeir
Reply all
Reply to author
Forward
0 new messages